<p>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.</p>

<p>Any ideas?</p>

[{'answer_id': 22991, 'author': 'TheSmurf', 'author_id': 1975282, 'author_profile': 'https://Stackoverflow.com/users/1975282', 'pm_score': 4, 'selected': True, 'text': "<p>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.</p>\n\n<p>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.</p>\n"}, {'answer_id': 23010, 'author': 'Vincent', 'author_id': 1508, 'author_profile': 'https://Stackoverflow.com/users/1508', 'pm_score': 2, 'selected': False, 'text': '<p>Use the <a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.aspx" rel="nofollow noreferrer">TCPClient Class</a> to create a generic function that connects in TCP to a given IP address.</p>\n\n<p>Then iterate over the list of servers you want to test and try to open a connection to port 1433.</p>\n'}, {'answer_id': 23011, 'author': 'Stu', 'author_id': 414, 'author_profile': 'https://Stackoverflow.com/users/414', 'pm_score': 2, 'selected': False, 'text': '<p>If you need specific servers, use WMI. If you just want all available servers:</p>\n\n<p><a href="http://support.microsoft.com/kb/q287737/" rel="nofollow noreferrer">http://support.microsoft.com/kb/q287737/</a></p>\n'}, {'answer_id': 23019, 'author': 'Shaun Austin', 'author_id': 1120, 'author_profile': 'https://Stackoverflow.com/users/1120', 'pm_score': 0, 'selected': False, 'text': "<p>I would certainly go with Vincent's answer. Just make absolutely certain you are closing and disposing the tcp connections properly etc. WMI seems a bit of overkill to me if that is all you're after.</p>\n"}, {'answer_id': 451160, 'author': 'Benjamin Autin', 'author_id': 1440933, 'author_profile': 'https://Stackoverflow.com/users/1440933', 'pm_score': 2, 'selected': False, 'text': '<p><code>System.Data.Sql.SqlDataSourceEnumerator</code> will return all instances of SQL Server currently running.<br>\n<a href="http://msdn.microsoft.com/en-us/library/system.data.sql.sqldatasourceenumerator.aspx" rel="nofollow noreferrer">MSDN Link</a></p>\n'}, {'answer_id': 4217054, 'author': 'Vladimir', 'author_id': 512394, 'author_profile': 'https://Stackoverflow.com/users/512394', 'pm_score': 2, 'selected': False, 'text': '<p>SqlDataSourceEnumerator gives you all instances but they are not necessarily running.\nFor 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</p>\n'}]
['https://Stackoverflow.com/questions/22979', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/178/']