SQL Server Startup Detection

I am looking for a way to poll various servers and verify that the SQL server is up and running. I am writing my code in C #. I don't really care about individual databases, just that the SQL server is up and running.

Any ideas?

+6
c # sql-server
source share
6 answers

Well, a brute force solution should try to initiate a database connection on each server. This will tell you if it will work, although you may have timeout problems.

The more elegant (but more complicated ... isn't it?) Solution would be to use WMI to connect to a remote computer and find out if the SQL server process is running.

+5
source share

Use the TCPClient class to create a generic function that connects to TCP with a given IP address.

Then, go through the list of servers you want to test and try to open a connection to port 1433.

+2
source share

If you need specific servers, use WMI. If you just need all the available servers:

http://support.microsoft.com/kb/q287737/

+2
source share

System.Data.Sql.SqlDataSourceEnumerator will return all instances of SQL Server that are currently running.
MSDN Link

+2
source share

SqlDataSourceEnumerator provides you with all instances, but they do not necessarily work. For local SQL instances, you can use the ServiceController object, the System.ServiceProcess namespace. The service name is the union of "MSSQL $" and "InstanceName" from SqlDataSourceEnumerator. Set the ServiceName property of the ServiceController object, and you can check the Status property - Stopped, Startup, Delayed, etc. Consequently, you can filter "Launch"

+2
source share

I would certainly go with Vincent's answer. Just make sure you close and remove tcp connections properly, etc. WMI seems a little redundant to me if that is all you need.

0
source share

All Articles