I have a task that I am trying to complete and would appreciate direction, to know which is the most efficient path to take for future requirements.Use Case: A background process that determines if a specific database is broken. This task will be run every two minutes as we must know ASAP if there is a problem with the database.My Solution: Opening a connection with said database, if the conenction is refused - an email is then sent notifying the appropriate individuals.Here is the method I built to determine the DB state:    public bool DatabaseConnection()    {        bool statusUp = true;        using (var databaseConnection = new SqlConnection(ConfigData.ConnectionStrings.DatabaseConnectionString))        {            try            {                databaseConnection.Open()                   }            catch (SqlException ex)            {                const string message = Could not establish a connection with Database.;                Log.DatabaseStatusDown(message, ex);                statusUp = false;             }            finally { databaseConnection.Close(); }        }        return statusUp    }I am aware that the Using statement leverages the IDisposable class and will auto-dispose the connection, but I wanted to be extra cautious and included the finally statement out of paranoia. If anyone could please give me criticism, suggestions, recommendations or really anything that can help me improve this code I would greatly appreciate it. I am also open to different ideas on how I can determine if a DB is broken.
C# Method to determine database status
c#;sql;asp.net;database
Hmmm,There are a number of problems with your check.1: loss of network connectivity - DB may not be broken, but test will pass/fail, email not sent depending on what box your test is running on2: Database Table is deadlocked or other DB problem - Simple connection test will pass3: box on which test runs has crashed - test not run, no alert4: DB down for maintenance - lots of emails sentThere are infrastructure monitoring tools you can buy/download to do this kind of thing and let you set up multiple tests and conditions etc. Best just to use an off the shelf productAs to your code, I would add:bool statusUp = false; is better as it returns false if the test fails. set to true if it passesIf your code fails on the Connection constructor (say it cant read the config for example) the exception is not caught