Database status check and report
-
Hi all,I want to write an application(web or desktop) which will monitor different database status(status:conncetion error,running or down e.t.c) and report back to say:database1 is not down, oracle database2 is down or connection error etc. So I dont really have an idea where to start.Coding using C#.thanx.
-
Hi all,I want to write an application(web or desktop) which will monitor different database status(status:conncetion error,running or down e.t.c) and report back to say:database1 is not down, oracle database2 is down or connection error etc. So I dont really have an idea where to start.Coding using C#.thanx.
You could begin by something as simple as: 1) Make a connection to the database New SqlConnection(GetConnString()) 2) Open the connection SQLconn.Open() 3) Issue some sort of simple command SQLcmd = New SqlCommand("select count(*) from customers", SQLconn) 4) Get data from the DB r = SQLcmd.ExecuteScalar 5) Wrap all of this code in a Try-Catch block and if successful, then you can safely assume that your connection to the database is up and the database is running. Good luck :thumbsup:
-
Hi all,I want to write an application(web or desktop) which will monitor different database status(status:conncetion error,running or down e.t.c) and report back to say:database1 is not down, oracle database2 is down or connection error etc. So I dont really have an idea where to start.Coding using C#.thanx.
leketekoa wrote:
oracle database2 is
Did you start by looking for existing solutions? As an example you might want to start with the following in google: nagios oracle
leketekoa wrote:
nd report back
What that means can add significantly to scope of the project.
-
You could begin by something as simple as: 1) Make a connection to the database New SqlConnection(GetConnString()) 2) Open the connection SQLconn.Open() 3) Issue some sort of simple command SQLcmd = New SqlCommand("select count(*) from customers", SQLconn) 4) Get data from the DB r = SQLcmd.ExecuteScalar 5) Wrap all of this code in a Try-Catch block and if successful, then you can safely assume that your connection to the database is up and the database is running. Good luck :thumbsup:
try
{
//getting a connection string from App.config
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Database1"].ConnectionString);
con.Open();
//Testing if the database Opens
if (con.State == System.Data.ConnectionState.Open)
{
lblStatus.Text = "Connected";
lblStatus.BackColor = Color.Red;
//E-MAIL to the user that the conncetion was succesful;
//Closing the connection if Opened Succesful;
con.Close();
}
else
{
lblStatus.Text = "Not Connected";
//What to do if not opened??.
//E-MAIL to the user that the conncetion was UnSuccesful;
}
}
catch (Exception ef)
{
lblStatus.Text = Convert.ToString("Database Error (try-catched): "+ ef);
}@David Mujica Thank you very much :-D .From the above given code I wanna test each connection string(DataBase1,DataBase2...DatabaseN) from app.config with a loop in a try-Catch block.(Please note the connection strings are for SQL and Oracle) for example:
try
{
i=1;
//to loop all existing number of connection String
//if there are 10 different connection string loop.
while(Connection.String.Exist)
{if(Databasei.String.connect) { String connectMSGSuccess ="Connection String "+ i +" connects"; } else { String connectMSGunSuccess ="Connection String "+ i +" Couldn't connect"; } i++;
}
//Then I will insert the email code to send the (connectMSGunSuccess and connectMSGSuccess )Messages.
}
catch
{
//ill also email the error message here
lblStatus.Text -
You could begin by something as simple as: 1) Make a connection to the database New SqlConnection(GetConnString()) 2) Open the connection SQLconn.Open() 3) Issue some sort of simple command SQLcmd = New SqlCommand("select count(*) from customers", SQLconn) 4) Get data from the DB r = SQLcmd.ExecuteScalar 5) Wrap all of this code in a Try-Catch block and if successful, then you can safely assume that your connection to the database is up and the database is running. Good luck :thumbsup: