I'm looking for a way to poll different servers and check that SQL server is up and running. I'm writing my code in C#. I don't particularly care about individual databases, just that SQL server is running and responsive.
Any ideas?
Click Start, point to All Programs, point to Microsoft SQL Server, point to Configuration Tools, and then click SQL Server Configuration Manager. If you do not have these entries on the Start menu, SQL Server is not correctly installed.
Go to Start → Run, type cmd, and hit enter to open the command prompt. Step 2 -SQLCMD -S servername\instancename (where servernameb= the name of your server, and instancename is the name of the SQL instance). The prompt will change to 1→. Step 4 -At the 2→ prompt type go and hit enter.
In the SQL Server Configuration Manager, from the left pane select SQL Server Services. Now, some services will appear in the right pane. Now, each service in the right pane will have some icon. If the service have green triangle icon then, it means the service is running.
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.
System.Data.Sql.SqlDataSourceEnumerator
will return all instances of SQL Server currently running.
MSDN Link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With