Detecting If Sql Server Is Running
Solution 1:
Well, the brute force solution is to attempt to initiate a connection with the database on each server. That will tell you whether it's running, though you could have timeout issues.
The more elegant (but more difficult... isn't that always the way?) solution would be to use WMI to connect to the remote machine and find out if the SQL server process is running.
Solution 2:
System.Data.Sql.SqlDataSourceEnumerator will return all instances of SQL Server currently running.
MSDN Link
Solution 3:
Use the TCPClient Class to create a generic function that connects in TCP to a given IP address.
Then iterate over the list of servers you want to test and try to open a connection to port 1433.
Solution 4:
If you need specific servers, use WMI. If you just want all available servers:
Solution 5:
SqlDataSourceEnumerator gives you all instances but they are not necessarily running. For local instances of SQL, you can use ServiceController object, namespace System.ServiceProcess. Service name is concatination of "MSSQL$" and "InstanceName" from SqlDataSourceEnumerator. Set ServiceName property of the ServiceController object, and you can check "Status" property - Stopped, Running, Pended etc. Hence, you can filter "Running" ones
Post a Comment for "Detecting If Sql Server Is Running"