Database: Fix Logging of errors with sql queries
This commit is contained in:
parent
cd3646dca0
commit
10d8e7749a
@ -1,10 +1,7 @@
|
|||||||
Imports System.ComponentModel
|
Imports System.ComponentModel
|
||||||
Imports System.Data.Common
|
|
||||||
Imports System.Data.SqlClient
|
Imports System.Data.SqlClient
|
||||||
Imports DigitalData.Modules.Encryption
|
Imports DigitalData.Modules.Encryption
|
||||||
Imports DigitalData.Modules.Logging
|
Imports DigitalData.Modules.Logging
|
||||||
Imports DigitalData.Modules.Base
|
|
||||||
Imports System.Threading
|
|
||||||
|
|
||||||
Public Class MSSQLServer
|
Public Class MSSQLServer
|
||||||
Implements IDatabase
|
Implements IDatabase
|
||||||
@ -206,10 +203,13 @@ Public Class MSSQLServer
|
|||||||
Dim oDecryptedConnectionString = DecryptConnectionString(pConnectionString)
|
Dim oDecryptedConnectionString = DecryptConnectionString(pConnectionString)
|
||||||
Dim oConnection As New SqlConnection(oDecryptedConnectionString)
|
Dim oConnection As New SqlConnection(oDecryptedConnectionString)
|
||||||
OpenSQLConnection(oConnection)
|
OpenSQLConnection(oConnection)
|
||||||
oConnection.Close()
|
oConnection?.Close()
|
||||||
Return True
|
Return True
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
Logger.Error("Error while testing connection!")
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
|
|
||||||
Return False
|
Return False
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
@ -220,11 +220,18 @@ Public Class MSSQLServer
|
|||||||
''' <param name="Connection"></param>
|
''' <param name="Connection"></param>
|
||||||
''' <returns></returns>
|
''' <returns></returns>
|
||||||
Private Function OpenSQLConnection(Connection As SqlConnection) As SqlConnection
|
Private Function OpenSQLConnection(Connection As SqlConnection) As SqlConnection
|
||||||
If Connection.State = ConnectionState.Closed Then
|
Try
|
||||||
Connection.Open()
|
If Connection.State = ConnectionState.Closed Then
|
||||||
End If
|
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
|
End Function
|
||||||
|
|
||||||
<DebuggerStepThrough()>
|
<DebuggerStepThrough()>
|
||||||
@ -242,6 +249,7 @@ Public Class MSSQLServer
|
|||||||
|
|
||||||
Return oConnection
|
Return oConnection
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
Logger.Error("Connection could not be created or opened!")
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
|
|
||||||
Return Nothing
|
Return Nothing
|
||||||
@ -260,7 +268,9 @@ Public Class MSSQLServer
|
|||||||
Dim oConnectionString = pConnectionString.Replace(oBuilder.Password, "XXXXX")
|
Dim oConnectionString = pConnectionString.Replace(oBuilder.Password, "XXXXX")
|
||||||
Return oConnectionString
|
Return oConnectionString
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
Logger.Error("ConnectionString is invalid and could not be masked!")
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
|
|
||||||
Return "Invalid ConnectionString"
|
Return "Invalid ConnectionString"
|
||||||
End Try
|
End Try
|
||||||
End Function
|
End Function
|
||||||
@ -345,8 +355,8 @@ Public Class MSSQLServer
|
|||||||
End Using
|
End Using
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
Logger.Error("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", pSqlCommandObject.CommandText)
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
Logger.Warn("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", pSqlCommandObject.CommandText)
|
|
||||||
Throw ex
|
Throw ex
|
||||||
Finally
|
Finally
|
||||||
MaybeCommitTransaction(oTransaction, pTransactionMode)
|
MaybeCommitTransaction(oTransaction, pTransactionMode)
|
||||||
@ -436,8 +446,9 @@ Public Class MSSQLServer
|
|||||||
|
|
||||||
Return True
|
Return True
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
|
Logger.Error("ExecuteNonQueryWithConnectionObject: Error in ExecuteNonQueryWithConnectionObject while executing command: [{0}]", pSqlCommandObject.CommandText)
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
Logger.Warn("ExecuteNonQueryWithConnectionObject: Error in ExecuteNonQueryWithConnectionObject while executing command: [{0}]", pSqlCommandObject.CommandText)
|
|
||||||
Return False
|
Return False
|
||||||
Finally
|
Finally
|
||||||
MaybeCommitTransaction(oTransaction, pTransactionMode)
|
MaybeCommitTransaction(oTransaction, pTransactionMode)
|
||||||
@ -518,7 +529,7 @@ Public Class MSSQLServer
|
|||||||
|
|
||||||
Try
|
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.Connection = pSqlConnection
|
||||||
pSqlCommandObject.CommandTimeout = pTimeout
|
pSqlCommandObject.CommandTimeout = pTimeout
|
||||||
@ -527,7 +538,7 @@ Public Class MSSQLServer
|
|||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Logger.Error(ex)
|
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
|
Finally
|
||||||
MaybeCommitTransaction(oTransaction, pTransactionMode)
|
MaybeCommitTransaction(oTransaction, pTransactionMode)
|
||||||
@ -562,7 +573,7 @@ Public Class MSSQLServer
|
|||||||
End Using
|
End Using
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
Logger.Warn($"GetScalarValue failed SQLCommand [{pSqlCommand}]")
|
Logger.Error($"GetScalarValue failed SQLCommand [{pSqlCommand}]")
|
||||||
|
|
||||||
Return Nothing
|
Return Nothing
|
||||||
End Try
|
End Try
|
||||||
@ -594,7 +605,7 @@ Public Class MSSQLServer
|
|||||||
End Using
|
End Using
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
Logger.Warn($"NewExecuteNonQueryAsync failed SQLCommand [{SqlCommand}]")
|
Logger.Error($"NewExecuteNonQueryAsync failed SQLCommand [{SqlCommand}]")
|
||||||
|
|
||||||
End Try
|
End Try
|
||||||
End Sub
|
End Sub
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user