Check Sql Connection
Checks whether a given SqlConnection can be successfully opened.
If the connection is already open, it is closed immediately after the check. If an exception occurs during the attempt to open the connection, the function returns False .
VB
Public Function CheckSqlConnection(MyConnection As SqlConnection) As Boolean
Try
If Not MyConnection.State = ConnectionState.Open Then MyConnection.Open()
Catch ex As Exception
Return False
End Try
If MyConnection.State = ConnectionState.Open Then MyConnection.Close()
Return True
End Function