diff --git a/Database/Adapters/MSSQLServer.vb b/Database/Adapters/MSSQLServer.vb index d4477c5b..09f7e8a3 100644 --- a/Database/Adapters/MSSQLServer.vb +++ b/Database/Adapters/MSSQLServer.vb @@ -1,10 +1,7 @@ Imports System.ComponentModel -Imports System.Data.Common Imports System.Data.SqlClient Imports DigitalData.Modules.Encryption Imports DigitalData.Modules.Logging -Imports DigitalData.Modules.Base -Imports System.Threading Public Class MSSQLServer Implements IDatabase @@ -206,10 +203,13 @@ Public Class MSSQLServer Dim oDecryptedConnectionString = DecryptConnectionString(pConnectionString) Dim oConnection As New SqlConnection(oDecryptedConnectionString) OpenSQLConnection(oConnection) - oConnection.Close() + oConnection?.Close() Return True + Catch ex As Exception + Logger.Error("Error while testing connection!") Logger.Error(ex) + Return False End Try End Function @@ -220,11 +220,18 @@ Public Class MSSQLServer ''' ''' Private Function OpenSQLConnection(Connection As SqlConnection) As SqlConnection - If Connection.State = ConnectionState.Closed Then - Connection.Open() - End If + Try + If Connection.State = ConnectionState.Closed Then + Connection.Open() + End If - Return Connection + Return Connection + Catch ex As Exception + Logger.Error("Error while opening Connection!") + Logger.Error(ex) + + Throw ex + End Try End Function @@ -242,6 +249,7 @@ Public Class MSSQLServer Return oConnection Catch ex As Exception + Logger.Error("Connection could not be created or opened!") Logger.Error(ex) Return Nothing @@ -260,7 +268,9 @@ Public Class MSSQLServer Dim oConnectionString = pConnectionString.Replace(oBuilder.Password, "XXXXX") Return oConnectionString Catch ex As Exception + Logger.Error("ConnectionString is invalid and could not be masked!") Logger.Error(ex) + Return "Invalid ConnectionString" End Try End Function @@ -345,8 +355,8 @@ Public Class MSSQLServer End Using Catch ex As Exception + Logger.Error("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", pSqlCommandObject.CommandText) Logger.Error(ex) - Logger.Warn("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", pSqlCommandObject.CommandText) Throw ex Finally MaybeCommitTransaction(oTransaction, pTransactionMode) @@ -436,8 +446,9 @@ Public Class MSSQLServer Return True Catch ex As Exception + Logger.Error("ExecuteNonQueryWithConnectionObject: Error in ExecuteNonQueryWithConnectionObject while executing command: [{0}]", pSqlCommandObject.CommandText) Logger.Error(ex) - Logger.Warn("ExecuteNonQueryWithConnectionObject: Error in ExecuteNonQueryWithConnectionObject while executing command: [{0}]", pSqlCommandObject.CommandText) + Return False Finally MaybeCommitTransaction(oTransaction, pTransactionMode) @@ -518,7 +529,7 @@ Public Class MSSQLServer Try - Logger.Debug("GetScalarValueWithConnectionObject: Running Query [{0}] with Parameters [{1}]", pSqlCommandObject, GetParameterListAsString(pSqlCommandObject)) + Logger.Debug("GetScalarValueWithConnectionObject: Running Query [{0}] with Parameters [{1}]", pSqlCommandObject.CommandText, GetParameterListAsString(pSqlCommandObject)) pSqlCommandObject.Connection = pSqlConnection pSqlCommandObject.CommandTimeout = pTimeout @@ -527,7 +538,7 @@ Public Class MSSQLServer Catch ex As Exception Logger.Error(ex) - Logger.Warn("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", pSqlCommandObject) + Logger.Error("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", pSqlCommandObject.CommandText) Finally MaybeCommitTransaction(oTransaction, pTransactionMode) @@ -562,7 +573,7 @@ Public Class MSSQLServer End Using Catch ex As Exception Logger.Error(ex) - Logger.Warn($"GetScalarValue failed SQLCommand [{pSqlCommand}]") + Logger.Error($"GetScalarValue failed SQLCommand [{pSqlCommand}]") Return Nothing End Try @@ -594,7 +605,7 @@ Public Class MSSQLServer End Using Catch ex As Exception Logger.Error(ex) - Logger.Warn($"NewExecuteNonQueryAsync failed SQLCommand [{SqlCommand}]") + Logger.Error($"NewExecuteNonQueryAsync failed SQLCommand [{SqlCommand}]") End Try End Sub