title: In C# what is the best way to determine if a database is up and running?
body: <p>I have come up with the following method to determine is a database is up and running.  This trys to open a database connection and if it fails it return false.</p>
  
  <pre><code>private static bool IsDatabaseConnectionUp(string connectionString)
  {
      System.Data.SqlClient.SqlConnection conn = null;
  
      try
      {
          conn = new SqlConnection(connectionString);
  
          conn.Open();
  
          return conn.State == System.Data.ConnectionState.Open;
      }
      catch (SqlException)
      {
          // There was an error in opening the database so it is must not up.
          return false;
      }
      finally
      {
          if (conn != null)
          {
              if (conn.State == System.Data.ConnectionState.Open)
              {
                  conn.Close();
              }
  
              conn.Dispose();
          }
      }
  }
  </code></pre>
  
  <p>Is this the best way to determine if this database is up?  The reason I do not like this method it will rely on the timeout value, and will take as long as the timeout is set.  </p>
  
  <p>Is there a better way?</p>