Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the fastest method to check SQL server availability?

Tags:

c#

sql-server

smo

What's the best method to check if SQL server exists or not?

I'm trying Microsoft.SqlServer.Management.Smo.Server.PingSqlServerVersion() and it works fine if server exists and available. But it kinda pretty slow, if there is no such a server.

Is there any fast enough method to check without even defining user credentials (only the server name), if a server exists?

What do you recommend to use?

like image 983
iLemming Avatar asked Jul 15 '10 15:07

iLemming


1 Answers

You could still use Microsoft.SqlServer.Management.Smo.Server.PingSqlServerVersion() but use it asynchronously. e.g. you could call it via a BackWorker class. The DoWork event would call Microsoft.SqlServer.Management.Smo.Server.PingSqlServerVersion(). The RunWorkerCompleted would just set a boolean variable to true. THat way you could fire it off, wait however long you wanted, check the boolean value and if it was not true then you would know that the SQL server had not responded yet and you could cancel the BackgroundWorker.

like image 69
Ben Robinson Avatar answered Sep 26 '22 23:09

Ben Robinson