What's the fastest way to check the availability of a SQL Server server?
Posted
by mwolfe02
on Stack Overflow
See other posts from Stack Overflow
or by mwolfe02
Published on 2010-01-28T16:50:12Z
Indexed on
2010/03/24
13:23 UTC
Read the original article
Hit count: 291
I have an MS Access program in use in multiple locations. It connects to MS SQL Server tables, but the server name is different in each location. I am looking for the fastest way to test for the existence of a server. The code I am currently using looks like this:
ShellWait "sc \\" & ServerName & " qdescription MSSQLSERVER > " & Qt(fn)
FNum = FreeFile()
Open fn For Input As #FNum
Line Input #FNum, Result
Close #FNum
Kill fn
If InStr(Result, "SUCCESS") Then ...
ShellWait: executes a shell command and waits for it to finish
Qt: wraps a string in double quotes
fn: temporary filename variable
I run the above code against a list of server names (of which only one is normally available). The code takes about one second if the server is available and takes about 8 seconds for each server that is unavailable. I'd like to get both of these lower, if possible, but especially the fail case as this one happens most often.
© Stack Overflow or respective owner