diff --git a/Modules.Database/BaseClass.vb b/Modules.Database/BaseClass.vb deleted file mode 100644 index c5400025..00000000 --- a/Modules.Database/BaseClass.vb +++ /dev/null @@ -1,5 +0,0 @@ -Public MustInherit Class BaseClass - Public MustOverride Function GetDatatable(SqlCommand As String) As DataTable - Public MustOverride Function GetScalarValue(SqlCommand As String) As Object - Public MustOverride Function ExecuteNonQuery(SqlCommand As String) As Boolean -End Class diff --git a/Modules.Database/Database.vbproj b/Modules.Database/Database.vbproj index d81dd7c2..4188cab7 100644 --- a/Modules.Database/Database.vbproj +++ b/Modules.Database/Database.vbproj @@ -90,7 +90,6 @@ - diff --git a/Modules.Database/Firebird.vb b/Modules.Database/Firebird.vb index bac43c79..6eb0caf6 100644 --- a/Modules.Database/Firebird.vb +++ b/Modules.Database/Firebird.vb @@ -46,8 +46,6 @@ Imports DigitalData.Modules.Logging ''' REMARKS: If the connection fails due to "wrong username or password", the cause might be that the server harddrive is full.. ''' Public Class Firebird - Inherits BaseClass - Private _Logger As Logger Private _LogConfig As LogConfig Private _connectionServer As String @@ -221,7 +219,7 @@ Public Class Firebird ''' ''' The command to execute ''' True, if command was executed sucessfully. Otherwise false. - Public Overrides Function ExecuteNonQuery(SqlCommand As String) As Boolean + Public Function ExecuteNonQuery(SqlCommand As String) As Boolean Dim oConnection As FbConnection = GetConnection() Dim oScalarValue As Object = ExecuteNonQueryWithConnection(SqlCommand, oConnection) oConnection.Close() @@ -268,7 +266,7 @@ Public Class Firebird ''' ''' The query to execute ''' The scalar value if the command was executed successfully. Nothing otherwise. - Public Overrides Function GetScalarValue(SqlQuery As String) As Object + Public Function GetScalarValue(SqlQuery As String) As Object Dim oConnection As FbConnection = GetConnection() Dim oScalarValue As Object = GetScalarValueWithConnection(SqlQuery, oConnection) oConnection.Close() @@ -304,7 +302,8 @@ Public Class Firebird oAdapter.Fill(oDatatable) Catch ex As Exception - _Logger.Error(ex, $"Error in GetDatatableWithConnection while executing command: '{SqlQuery}'") + _Logger.Error(ex) + _Logger.Warn("Error in GetDatatableWithConnection while executing command: '{0}'", SqlQuery) Throw ex Finally MaybeCommitTransaction(oTransaction, TransactionMode) @@ -318,11 +317,17 @@ Public Class Firebird ''' ''' The query to execute ''' A datatable containing the results if the command was executed successfully. Nothing otherwise. - Public Overrides Function GetDatatable(SqlQuery As String) As DataTable - Dim oConnection As FbConnection = GetConnection() - Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection) - oConnection.Close() + Public Function GetDatatable(SqlQuery As String, Optional TransactionMode As TransactionMode = TransactionMode.NoTransaction, Optional Transaction As FbTransaction = Nothing) As DataTable + Try + Dim oConnection As FbConnection = GetConnection() + Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection, TransactionMode, Transaction) + oConnection.Close() - Return oDatatable + Return oDatatable + Catch ex As Exception + _Logger.Error(ex) + _Logger.Warn("Error in GetDatatable while executing command: '{0}'", SqlQuery) + Throw ex + End Try End Function End Class diff --git a/Modules.Database/MSSQLServer.vb b/Modules.Database/MSSQLServer.vb index 7b92e2eb..e8c79674 100644 --- a/Modules.Database/MSSQLServer.vb +++ b/Modules.Database/MSSQLServer.vb @@ -2,13 +2,11 @@ Imports DigitalData.Modules.Logging Public Class MSSQLServer - Inherits BaseClass - Public DBInitialized As Boolean = False Public CurrentSQLConnectionString As String = "" - Private _Timeout As Integer - Private _Logger As Logger + Private ReadOnly _Timeout As Integer + Private ReadOnly _Logger As Logger Public Sub New(LogConfig As LogConfig, ConnectionString As String, Optional Timeout As Integer = 120) _Logger = LogConfig.GetLogger() @@ -77,7 +75,7 @@ Public Class MSSQLServer ''' ''' sqlcommand for datatable (select XYZ from TableORView) ''' Returns a datatable - Public Overrides Function GetDatatable(SqlCommand As String) As DataTable + Public Function GetDatatable(SqlCommand As String, Timeout As Integer) As DataTable Try If TestCanConnect() = False Then Return Nothing @@ -86,7 +84,7 @@ Public Class MSSQLServer Using oConnection = GetSQLConnection() Using oSQLCOmmand = oConnection.CreateCommand() oSQLCOmmand.CommandText = SqlCommand - oSQLCOmmand.CommandTimeout = _Timeout + oSQLCOmmand.CommandTimeout = Timeout Dim dt As DataTable = New DataTable() Dim oAdapter As SqlDataAdapter = New SqlDataAdapter(oSQLCOmmand) @@ -101,6 +99,10 @@ Public Class MSSQLServer End Try End Function + Public Function GetDatatable(SqlCommand As String) As DataTable + Return GetDatatable(SqlCommand, _Timeout) + End Function + ''' ''' Executes the passed sql-statement ''' @@ -112,7 +114,7 @@ Public Class MSSQLServer Return ExecuteNonQuery(executeStatement) End Function - Public Overrides Function ExecuteNonQuery(SQLCommand As String) As Boolean + Public Function ExecuteNonQuery(SQLCommand As String, Timeout As Integer) As Boolean Try If TestCanConnect() = False Then Return Nothing @@ -121,7 +123,7 @@ Public Class MSSQLServer Using oConnection = GetSQLConnection() Using oSQLCOmmand = oConnection.CreateCommand() oSQLCOmmand.CommandText = SQLCommand - oSQLCOmmand.CommandTimeout = _Timeout + oSQLCOmmand.CommandTimeout = Timeout oSQLCOmmand.ExecuteNonQuery() Return True End Using @@ -133,6 +135,10 @@ Public Class MSSQLServer End Try End Function + Public Function ExecuteNonQuery(SQLCommand As String) As Boolean + Return ExecuteNonQuery(SQLCommand, _Timeout) + End Function + ''' ''' Executes the passed sql-statement as Scalar ''' @@ -143,7 +149,7 @@ Public Class MSSQLServer Return GetScalarValue(ScalarSQL) End Function - Public Overrides Function GetScalarValue(SQLQuery As String) As Object + Public Function GetScalarValue(SQLQuery As String, Timeout As Integer) As Object Try If TestCanConnect() = False Then Return Nothing @@ -152,7 +158,7 @@ Public Class MSSQLServer Using oConnection As SqlConnection = GetSQLConnection() Using oSQLCOmmand = oConnection.CreateCommand() oSQLCOmmand.CommandText = SQLQuery - oSQLCOmmand.CommandTimeout = _Timeout + oSQLCOmmand.CommandTimeout = Timeout Dim oResult As Object = oSQLCOmmand.ExecuteScalar() Return oResult End Using @@ -163,6 +169,10 @@ Public Class MSSQLServer End Try End Function + Public Function GetScalarValue(SQLQuery As String) As Object + Return GetScalarValue(SQLQuery, _Timeout) + End Function + ''' ''' Executes the passed sql-statement in asyncmode ''' diff --git a/Modules.Database/ODBC.vb b/Modules.Database/ODBC.vb index 07f343e0..2d95c07d 100644 --- a/Modules.Database/ODBC.vb +++ b/Modules.Database/ODBC.vb @@ -2,8 +2,6 @@ Imports DigitalData.Modules.Logging Public Class ODBC - Inherits BaseClass - Private _Logger As Logger Private _LogConfig As LogConfig @@ -88,7 +86,7 @@ Public Class ODBC ''' ''' The command to execute ''' True, if command was executed sucessfully. Otherwise false. - Public Overrides Function ExecuteNonQuery(SqlCommand As String) As Boolean + Public Function ExecuteNonQuery(SqlCommand As String) As Boolean Dim oConnection As OdbcConnection = GetConnection() Dim oScalarValue As Object = ExecuteNonQueryWithConnection(SqlCommand, oConnection) oConnection.Close() @@ -128,7 +126,7 @@ Public Class ODBC ''' ''' The query to execute ''' A datatable containing the results if the command was executed successfully. Nothing otherwise. - Public Overrides Function GetScalarValue(SqlQuery As String) As Object + Public Function GetScalarValue(SqlQuery As String) As Object Dim oConnection As OdbcConnection = GetConnection() Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection) oConnection.Close() @@ -171,7 +169,7 @@ Public Class ODBC ''' ''' The query to execute ''' A datatable containing the results if the command was executed successfully. Nothing otherwise. - Public Overrides Function GetDatatable(SqlQuery As String) As DataTable + Public Function GetDatatable(SqlQuery As String) As DataTable Dim oConnection As OdbcConnection = GetConnection() Dim oDatatable As DataTable = GetDatatableWithConnection(SqlQuery, oConnection) oConnection.Close()