Take the 2-minute tour ×

We need to check for the existence of a SQL server across all domains prior to attempting to connect to the server. We can loop through the list of servers on the local domain use SQLDataSourceEnumerator, but that takes a few seconds to load up and it only gets the local domain. We are using SQL Server 2005 and 2008 servers as well as .Net 2010. We don't want to attempt to connect and wait for the 30 second or more timeout that appears to be standard if the server doesn't exist.

Any suggestions would be helpful.

share|improve this question
BTW You can specify the connect timeout yourself. –  Martin Smith Nov 4 '12 at 12:25
Can you PING the server first? That doesn't guarantee the server has a running/listening sqlserver instance but can tell you something about the network path to that server. Keep in mind that wahtever method you use: it takes time...(there is no instant/guaranteed yes or no out of the box) –  rene Nov 4 '12 at 12:31
Check this thread on StackOverflow. maybe it is useful for u How can I determine installed SQL Server instances and their versions? –  Maryam Arshi Nov 4 '12 at 13:02

1 Answer 1

up vote 1 down vote accepted

Try to connect with a smaller timeout. You can set the timeout in the connection string:

Connect Timeout=2;

You can't check faster than this. If there is no SQL Server at the remote endpoint the TCP connection does not receive a response and times out. Because there is no (negative) response you can't tell if there is no server at all or just a very slow one.

So a timeout is the best you can do to determine if there is a server listening or not.

share|improve this answer

Your Answer


