Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Database status check and report

Database status check and report

Scheduled Pinned Locked Moved Database
csharpdatabaseoraclehelp
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leketekoa
    wrote on last edited by
    #1

    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.

    D J 2 Replies Last reply
    0
    • L leketekoa

      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.

      D Offline
      D Offline
      David Mujica
      wrote on last edited by
      #2

      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:

      L 2 Replies Last reply
      0
      • L leketekoa

        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.

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • D David Mujica

          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:

          L Offline
          L Offline
          leketekoa
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • D David Mujica

            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:

            L Offline
            L Offline
            leketekoa
            wrote on last edited by
            #5

            Thanx a lot.I even add more functionalities/Methods :-D

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups