'Is there a way to "ping" an SQL Server via System.Data.SqlClient to see if it's online and ready for queries?

Is there a way to "ping" an SQL Server instance via System.Data.SqlClient to see if it's online and ready to accept queries?

The simple code below can be used to find the available SQL Servers on the LAN. But if the list of data sources is saved for later use, how can each instance be "pinged" to see if it's still available?

I could of course send a simple query to each instance, such as Use _master Select @@Version, but with a long list that might take a while. If there was some simple function such as SomeInstance.IsAvailable, that would be much better.

Dim sqlEnumInst As SqlDataSourceEnumerator = SqlDataSourceEnumerator.Instance
Dim sqlEnumData As System.Data.DataTable = sqlEnumInst.GetDataSources()
For Each row As DataRow In sqlEnumData.Rows
    Dim srvn As String = row("ServerName").ToString
    Dim insn As String = row("InstanceName").ToString
    Dim svrStr As String = srvn & "\" & insn
    Console.WriteLine(svrStr)
Next


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source