Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting if SQL server is running

Tags:

c#

sql-server

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?

like image 206
steve_mtl Avatar asked Aug 22 '08 17:08

steve_mtl


People also ask

How do I know if SQL Server is running Windows 10?

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.

How do you check SQL Server is running or not using CMD?

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.

How can I tell if SQL Server is running on a remote computer?

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.


2 Answers

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.

like image 52
TheSmurf Avatar answered Nov 15 '22 21:11

TheSmurf


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

like image 25
Benjamin Autin Avatar answered Nov 15 '22 22:11

Benjamin Autin