Skip to content

Instantly share code, notes, and snippets.

@msarchet
Created September 28, 2010 14:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msarchet/601143 to your computer and use it in GitHub Desktop.
Save msarchet/601143 to your computer and use it in GitHub Desktop.
''' <summary>
''' Determines whether database connection valid [the specified connection string].
''' </summary>
''' <param name="ConnectionString">The connection string.</param>
''' <returns>
''' <c>true</c> if [is database connection valid] [the specified connection string]; otherwise, <c>false</c>.
''' </returns>
Public Function IsDatabaseConnectionValid(ByVal ConnectionString As String) As Boolean
Try
Using cn As New SqlClient.SqlConnection(ConnectionString)
cn.Open()
Return True
End Using
Catch Ex As Exception
Return False
End Try
End Function
'Use this to test your connection
If Not ScriptAssist.Utilities.Helper.IsDatabaseConnectionValid(Options.ConnectionString_Shared) Then
FixDataConnection()
End If
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment