At the moment I am using this code to check if the database is accessible:
public bool IsDatabaseOnline(string con)
{
bool isConnected = false;
SQLConnection connect = null;
try {
connect = new SQLConnection(con);
connect.Open();
isConnected = true;
} catch (Exception e) {
isConnected = false;
} finally {
if (connect != null)
connect.Close();
}
return isConnected;
}
While this code works fine, there is a disadvantage. If the server is not online it spends about 4 full seconds trying to open the connection before deciding that it is not available.
Is there a way to test the connection without trying to actually opening it and waiting for the timeout? Something like a database-equivalent of ping?