0

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.

Rick H.
  • 165
  • 1
  • 10
  • 1
    BTW You can specify the [connect timeout](http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnectionstringbuilder.connecttimeout.aspx) yourself. – Martin Smith Nov 04 '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 04 '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?](http://stackoverflow.com/questions/141154/how-can-i-determine-installed-sql-server-instances-and-their-versions) – Maryam Arshi Nov 04 '12 at 13:02

1 Answers1

1

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.

usr
  • 168,620
  • 35
  • 240
  • 369