I need to develop a single routine that will be fired each 5 minutes to check if a list of SQL Servers (10 to 12) are up and running.
I can try to obtain a simple query in each one of the servers but this means that I have to create a table, view or stored procedure in every server, even if I use any already made SP I need to have a registered user in each server too. The servers are not in the same physical location so having those requirements would be a complex task. Is there a way to simply "ping" from C# one SQL Server?
Thanks in advance!
Look for an open listener on port 1433 (the default port). If you get any response after creating a tcp connection there, the server's probably up.
Similar to the answer offered by Andrew, but I use:
Select GetDate() as CurrentDate
This allows me to see if the SQL Server and the client have any time zone difference issues, in the same action.
For what Joel Coehorn suggested, have you already tried the utility named tcping. I know this is something you are not doing programmatically. It is a standalone executable which allows you to ping every specified time interval. It is not in C# though. Also..I am not sure If this would work If the target machine has firewall..hmmm..
[I am kinda new to this site and mistakenly added this as a comment, now added this as an answer. Let me know If this can be done here as I have duplicate comments (as comment and as an answer) here. I can not delete comments here.]
See the following project on GitHub: https://github.com/ghuntley/csharp-mssql-connectivity-tester
Connecting to mssql via C# is very problematic.
The handles will not be consistent once we connect, although we have close the connection after connect.
I did read somewhere it was .Net 4.0 issue, and if you use .Net 3.5 it should be ok.