diff --git a/Modules.Database/MSSQLServer.vb b/Modules.Database/MSSQLServer.vb index 3e9f5407..849775d7 100644 --- a/Modules.Database/MSSQLServer.vb +++ b/Modules.Database/MSSQLServer.vb @@ -66,7 +66,7 @@ Public Class MSSQLServer Public Function GetConnection() As SqlConnection Try Dim oConnection = GetSQLConnection() - oConnection.Open() + OpenSQLConnection(oConnection) Return oConnection Catch ex As Exception @@ -151,7 +151,7 @@ Public Class MSSQLServer Try _Logger.Debug("Testing connection to [{0}]", MaskConnectionString(ConnectionString)) Dim oConnection As New SqlConnection(ConnectionString) - oConnection.Open() + OpenSQLConnection(oConnection) oConnection.Close() Return True Catch ex As Exception @@ -169,10 +169,7 @@ Public Class MSSQLServer _Logger.Debug("Testing connection to [{0}]", MaskConnectionString(Connection.ConnectionString)) - If Connection.State = ConnectionState.Closed Then - Connection.Open() - End If - + OpenSQLConnection(Connection) Connection.Close() Return True Catch ex As Exception @@ -181,6 +178,18 @@ Public Class MSSQLServer End Try End Function + Private Function OpenSQLConnection(Connection As SqlConnection) As SqlConnection + Try + If Connection.State = ConnectionState.Closed Then + Connection.Open() + End If + Catch ex As Exception + _Logger.Error(ex) + End Try + + Return Connection + End Function + Private Function GetSQLConnection() As SqlConnection Return GetConnection(CurrentSQLConnectionString) End Function @@ -188,7 +197,7 @@ Public Class MSSQLServer Private Function GetConnection(ConnectionString As String) As SqlConnection Try Dim oConnection As New SqlConnection(ConnectionString) - oConnection.Open() + OpenSQLConnection(oConnection) Dim oMaskedConnectionString = MaskConnectionString(ConnectionString) _Logger.Debug("The Following Connection is open: {0}", oMaskedConnectionString)