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?
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.