Right now I'm by using this code to see if the database is obtainable:

public bool IsDatabaseOnline(string con)
    bool isConnected = false;
    SQLConnection connect = null;

    try {
        connect = new SQLConnection(con);
        isConnected = true;

    } catch (Exception e) {
        isConnected = false;

    } finally {
        if (connect != null)

    return isConnected;

Although this code works fine, there's a drawback. When the server isn't online it stays about 4 full seconds attempting to open the bond before determining that it's unavailable.

It is possible to method to test the bond without attempting to really opening it and awaiting the timeout? Something similar to a database-same as ping?

You can just alter the connection timeout to become shorter. Perform some testing and find out how low you are able to go but still be reliable. I wager you can get near to 500ms.


It depends.

You can always note what port your server listens on, after which try to connect with that directly having a socket. Then should you succeed, you are able to "assume" it's online, but it might not be based on your network atmosphere. This is the most "ping" like approach though. Obviously, it might be another thing is listening there, but that is most likely unlikely inside a standard atmosphere in which the DB is simply lower temporarily.

Also, in case your DB is on the devoted machine, you can really ping it. But which will only see if the equipment expires, not the DB server.

The ultimate option, is always to possess some background server constantly monitoring the DB server, so when it picks up it's offline, it marks something properly. Your application would then check that factor (effectively a cache) and it might be virtually immediate. Obviously, this means that it could give false-disadvantages (i.e. the server might be online however the monitoring service has not up-to-date the cache yet).