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.
Try to connect with a smaller timeout. You can set the timeout in the connection string:
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.