Merge branch 'Database_SqlConnection'
This commit is contained in:
commit
3a26343083
17
Database.Test/Database.Test.vbproj
Normal file
17
Database.Test/Database.Test.vbproj
Normal file
@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<RootNamespace>Database.Test</RootNamespace>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.1.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
12
Database.Test/UnitTest1.vb
Normal file
12
Database.Test/UnitTest1.vb
Normal file
@ -0,0 +1,12 @@
|
||||
Imports Microsoft.VisualStudio.TestTools.UnitTesting
|
||||
|
||||
Namespace Database.Test
|
||||
<TestClass>
|
||||
Public Class UnitTest1
|
||||
<TestMethod>
|
||||
Sub TestSub()
|
||||
|
||||
End Sub
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
@ -4,6 +4,7 @@ Imports System.Data.SqlClient
|
||||
Imports DigitalData.Modules.Encryption
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Base
|
||||
Imports System.Threading
|
||||
|
||||
Public Class MSSQLServer
|
||||
Implements IDatabase
|
||||
@ -264,118 +265,174 @@ Public Class MSSQLServer
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetDatatable(SqlCommand As String) As DataTable Implements IDatabase.GetDatatable
|
||||
Return GetDatatable(SqlCommand, QueryTimeout)
|
||||
''' <summary>
|
||||
''' Returns a Datatable for a SQL Statement
|
||||
''' </summary>
|
||||
''' <param name="pSqlCommand">SQL Command Text for Datatable (select XYZ from TableORView)</param>
|
||||
''' <returns>A datatable</returns>
|
||||
Public Function GetDatatable(pSqlCommand As String, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable Implements IDatabase.GetDatatable
|
||||
Using oSqlConnection = GetSQLConnection()
|
||||
Return GetDatatableWithConnectionObject(pSqlCommand, oSqlConnection, TransactionMode.WithTransaction, Nothing, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Returns a datatable for a sql-statement
|
||||
''' Returns a datatable for a SQL Statement
|
||||
''' </summary>
|
||||
''' <param name="SqlCommand">sqlcommand for datatable (select XYZ from TableORView)</param>
|
||||
''' <returns>Returns a datatable</returns>
|
||||
Public Function GetDatatable(SqlCommand As String, Timeout As Integer) As DataTable Implements IDatabase.GetDatatable
|
||||
''' <param name="pSqlCommandObject">SQL Command Object for Datatable (select XYZ from TableORView)</param>
|
||||
''' <returns>A datatable</returns>
|
||||
Public Function GetDatatable(pSqlCommandObject As SqlCommand, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable Implements IDatabase.GetDatatable
|
||||
Using oSqlConnection = GetSQLConnection()
|
||||
Return GetDatatableWithConnectionObject(SqlCommand, oSqlConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
Return GetDatatableWithConnectionObject(pSqlCommandObject, oSqlConnection, TransactionMode.WithTransaction, Nothing, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetDatatable(SqlCommand As String, Transaction As SqlTransaction, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Public Function GetDatatable(pSqlCommand As String, pTransaction As SqlTransaction, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Using oSqlConnection = GetSQLConnection()
|
||||
Return GetDatatableWithConnectionObject(SqlCommand, oSqlConnection, TransactionMode.ExternalTransaction, Transaction, Timeout)
|
||||
Return GetDatatableWithConnectionObject(pSqlCommand, oSqlConnection, TransactionMode.ExternalTransaction, pTransaction, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Async Function GetDatatableAsync(SqlCommand As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of DataTable)
|
||||
Return Await Task.Run(Function() GetDatatable(SqlCommand, Timeout))
|
||||
Public Function GetDatatable(pSqlCommandObject As SqlCommand, pTransaction As SqlTransaction, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Using oSqlConnection = GetSQLConnection()
|
||||
Return GetDatatableWithConnectionObject(pSqlCommandObject, oSqlConnection, TransactionMode.ExternalTransaction, pTransaction, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetDatatableWithConnection(SqlCommand As String, pConnectionString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Public Async Function GetDatatableAsync(pSqlCommand As String, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of DataTable)
|
||||
Return Await Task.Run(Function() GetDatatable(pSqlCommand, pTimeout))
|
||||
End Function
|
||||
|
||||
Public Async Function GetDatatableAsync(pSqlCommandObject As SqlCommand, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of DataTable)
|
||||
Return Await Task.Run(Function() GetDatatable(pSqlCommandObject, pTimeout))
|
||||
End Function
|
||||
|
||||
Public Function GetDatatableWithConnection(pSqlCommand As String, pConnectionString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Using oConnection = GetConnection(pConnectionString)
|
||||
Return GetDatatableWithConnectionObject(SqlCommand, oConnection, Timeout:=Timeout)
|
||||
Return GetDatatableWithConnectionObject(pSqlCommand, oConnection, pTimeout:=Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Function GetDatatableWithConnectionObject(SqlCommand As String, SqlConnection As SqlConnection,
|
||||
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional Transaction As SqlTransaction = Nothing,
|
||||
Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
||||
Public Function GetDatatableWithConnection(pSqlCommandObject As SqlCommand, pConnectionString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Using oConnection = GetConnection(pConnectionString)
|
||||
Return GetDatatableWithConnectionObject(pSqlCommandObject, oConnection, pTimeout:=Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Function GetDatatableWithConnectionObject(pSqlCommand As String, pSqlConnection As SqlConnection,
|
||||
Optional pTransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional pTransaction As SqlTransaction = Nothing,
|
||||
Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Dim oSQLCommand As New SqlCommand(pSqlCommand)
|
||||
Return GetDatatableWithConnectionObject(oSQLCommand, pSqlConnection, pTransactionMode, pTransaction, pTimeout)
|
||||
End Function
|
||||
|
||||
Public Function GetDatatableWithConnectionObject(pSqlCommandObject As SqlCommand, pSqlConnection As SqlConnection,
|
||||
Optional pTransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional pTransaction As SqlTransaction = Nothing,
|
||||
Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(pSqlConnection, pTransactionMode, pTransaction)
|
||||
Dim oTable As New DataTable() With {.TableName = Constants.DEFAULT_TABLE}
|
||||
|
||||
Try
|
||||
Dim oAdapter As New SqlDataAdapter(New SqlCommand With {
|
||||
.CommandText = SqlCommand,
|
||||
.Connection = SqlConnection,
|
||||
.Transaction = oTransaction,
|
||||
.CommandTimeout = Timeout
|
||||
})
|
||||
pSqlCommandObject.Connection = pSqlConnection
|
||||
pSqlCommandObject.Transaction = oTransaction
|
||||
pSqlCommandObject.CommandTimeout = pTimeout
|
||||
|
||||
Logger.Debug("GetDatatableWithConnectionObject: Running Query [{0}]", SqlCommand)
|
||||
Using oAdapter As New SqlDataAdapter(pSqlCommandObject)
|
||||
Logger.Debug("GetDatatableWithConnectionObject: Running Query [{0}]", pSqlCommandObject.CommandText)
|
||||
oAdapter.Fill(oTable)
|
||||
End Using
|
||||
|
||||
oAdapter.Fill(oTable)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", SqlCommand)
|
||||
Logger.Warn("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", pSqlCommandObject)
|
||||
Throw ex
|
||||
Finally
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
MaybeCommitTransaction(oTransaction, pTransactionMode)
|
||||
End Try
|
||||
|
||||
Return oTable
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function ExecuteNonQuery(SQLCommand As String) As Boolean Implements IDatabase.ExecuteNonQuery
|
||||
Public Function ExecuteNonQuery(pSQLCommand As String) As Boolean Implements IDatabase.ExecuteNonQuery
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return ExecuteNonQueryWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, QueryTimeout)
|
||||
Return ExecuteNonQueryWithConnectionObject(pSQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, QueryTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function ExecuteNonQuery(SQLCommand As String, Timeout As Integer) As Boolean Implements IDatabase.ExecuteNonQuery
|
||||
Public Function ExecuteNonQuery(pSQLCommandObject As SqlCommand) As Boolean
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return ExecuteNonQueryWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
Return ExecuteNonQueryWithConnectionObject(pSQLCommandObject, oConnection, TransactionMode.WithTransaction, Nothing, QueryTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function ExecuteNonQuery(SQLCommand As String, Transaction As SqlTransaction, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Boolean
|
||||
Public Function ExecuteNonQuery(pSQLCommand As String, pTimeout As Integer) As Boolean Implements IDatabase.ExecuteNonQuery
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return ExecuteNonQueryWithConnectionObject(SQLCommand, Transaction.Connection, TransactionMode.ExternalTransaction, Transaction, Timeout)
|
||||
Return ExecuteNonQueryWithConnectionObject(pSQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Async Function ExecuteNonQueryAsync(SQLCommand As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of Boolean)
|
||||
Return Await Task.Run(Function() ExecuteNonQuery(SQLCommand, Timeout))
|
||||
Public Function ExecuteNonQuery(pSQLCommandObject As SqlCommand, pTimeout As Integer) As Boolean
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return ExecuteNonQueryWithConnectionObject(pSQLCommandObject, oConnection, TransactionMode.WithTransaction, Nothing, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
|
||||
Public Function ExecuteNonQuery(pSQLCommand As String, pTransaction As SqlTransaction, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Boolean
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return ExecuteNonQueryWithConnectionObject(pSQLCommand, pTransaction.Connection, TransactionMode.ExternalTransaction, pTransaction, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Function ExecuteNonQuery(pSQLCommandObject As SqlCommand, pTransaction As SqlTransaction, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Boolean
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return ExecuteNonQueryWithConnectionObject(pSQLCommandObject, pTransaction.Connection, TransactionMode.ExternalTransaction, pTransaction, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Async Function ExecuteNonQueryAsync(pSQLCommand As String, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of Boolean)
|
||||
Return Await Task.Run(Function() ExecuteNonQuery(pSQLCommand, pTimeout))
|
||||
End Function
|
||||
|
||||
Public Async Function ExecuteNonQueryAsync(pSQLCommandObject As SqlCommand, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of Boolean)
|
||||
Return Await Task.Run(Function() ExecuteNonQuery(pSQLCommandObject, pTimeout))
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function ExecuteNonQueryWithConnection(pSQLCommand As String, ConnString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Boolean
|
||||
Using oConnection = GetConnection(ConnString)
|
||||
Return ExecuteNonQueryWithConnectionObject(pSQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Function ExecuteNonQueryWithConnectionObject(SqlCommand As String, SqlConnection As SqlConnection,
|
||||
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional Transaction As SqlTransaction = Nothing,
|
||||
Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Boolean
|
||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
||||
Public Function ExecuteNonQueryWithConnection(pSQLCommandObject As SqlCommand, ConnString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Boolean
|
||||
Using oConnection = GetConnection(ConnString)
|
||||
Return ExecuteNonQueryWithConnectionObject(pSQLCommandObject, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Function ExecuteNonQueryWithConnectionObject(pSqlCommand As String, pSqlConnection As SqlConnection,
|
||||
Optional pTransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional pTransaction As SqlTransaction = Nothing,
|
||||
Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Boolean
|
||||
Dim oSQLCommand As New SqlCommand(pSqlCommand)
|
||||
Return ExecuteNonQueryWithConnectionObject(oSQLCommand, pSqlConnection, pTransactionMode, pTransaction, pTimeout)
|
||||
End Function
|
||||
|
||||
Public Function ExecuteNonQueryWithConnectionObject(pSqlCommandObject As SqlCommand, pSqlConnection As SqlConnection,
|
||||
Optional pTransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional pTransaction As SqlTransaction = Nothing,
|
||||
Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Boolean
|
||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(pSqlConnection, pTransactionMode, pTransaction)
|
||||
|
||||
Try
|
||||
Logger.Debug("ExecuteNonQueryWithConnectionObject: Running Command [{0}]", SqlCommand)
|
||||
Logger.Debug("ExecuteNonQueryWithConnectionObject: Running Command [{0}]", pSqlCommandObject.CommandText)
|
||||
|
||||
Using oSQLCOmmand = SqlConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = SqlCommand
|
||||
oSQLCOmmand.CommandTimeout = Timeout
|
||||
oSQLCOmmand.Transaction = oTransaction
|
||||
oSQLCOmmand.ExecuteNonQuery()
|
||||
End Using
|
||||
pSqlCommandObject.Connection = pSqlConnection
|
||||
pSqlCommandObject.Transaction = oTransaction
|
||||
pSqlCommandObject.CommandTimeout = pTimeout
|
||||
pSqlCommandObject.ExecuteNonQuery()
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
@ -383,96 +440,126 @@ Public Class MSSQLServer
|
||||
Logger.Warn("ExecuteNonQueryWithConnectionObject: Error in ExecuteNonQueryWithConnectionObject while executing command: [{0}]-[{1}]", SqlCommand, SqlConnection.ConnectionString)
|
||||
Return False
|
||||
Finally
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
MaybeCommitTransaction(oTransaction, pTransactionMode)
|
||||
End Try
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetScalarValue(SQLQuery As String) As Object Implements IDatabase.GetScalarValue
|
||||
Public Function GetScalarValue(pSqlQuery As String) As Object Implements IDatabase.GetScalarValue
|
||||
Using oConnection As SqlConnection = GetSQLConnection()
|
||||
Return GetScalarValueWithConnectionObject(SQLQuery, oConnection)
|
||||
Return GetScalarValueWithConnectionObject(pSqlQuery, oConnection)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetScalarValue(SQLCommand As String, Timeout As Integer) As Object Implements IDatabase.GetScalarValue
|
||||
Public Function GetScalarValue(pSqlCommandObject As SqlCommand) As Object
|
||||
Using oConnection As SqlConnection = GetSQLConnection()
|
||||
Return GetScalarValueWithConnectionObject(pSqlCommandObject, oConnection)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValue(pSqlCommand As String, pTimeout As Integer) As Object Implements IDatabase.GetScalarValue
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return GetScalarValueWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
Return GetScalarValueWithConnectionObject(pSqlCommand, oConnection, TransactionMode.WithTransaction, Nothing, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetScalarValue(SQLCommand As String, Transaction As SqlTransaction, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Public Function GetScalarValue(pSqlCommandObject As SqlCommand, pTimeout As Integer) As Object
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return GetScalarValueWithConnectionObject(SQLCommand, oConnection, TransactionMode.ExternalTransaction, Transaction, Timeout)
|
||||
Return GetScalarValueWithConnectionObject(pSqlCommandObject, oConnection, TransactionMode.WithTransaction, Nothing, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Async Function GetScalarValueAsync(SQLQuery As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of Object)
|
||||
Return Await Task.Run(Function() GetScalarValue(SQLQuery, Timeout))
|
||||
Public Function GetScalarValue(pSQLCommand As String, pTransaction As SqlTransaction, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return GetScalarValueWithConnectionObject(pSQLCommand, oConnection, TransactionMode.ExternalTransaction, pTransaction, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetScalarValueWithConnection(SQLCommand As String, pConnectionString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Public Function GetScalarValue(pSQLCommandObject As SqlCommand, pTransaction As SqlTransaction, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Using oConnection = GetSQLConnection()
|
||||
Return GetScalarValueWithConnectionObject(pSQLCommandObject, oConnection, TransactionMode.ExternalTransaction, pTransaction, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Async Function GetScalarValueAsync(pSQLCommand As String, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of Object)
|
||||
Return Await Task.Run(Function() GetScalarValue(pSQLCommand, pTimeout))
|
||||
End Function
|
||||
|
||||
Public Async Function GetScalarValueAsync(pSQLCommandObject As SqlCommand, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Task(Of Object)
|
||||
Return Await Task.Run(Function() GetScalarValue(pSQLCommandObject, pTimeout))
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValueWithConnection(pSQLCommand As String, pConnectionString As String, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Using oConnection = GetConnection(pConnectionString)
|
||||
Return GetScalarValueWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
Return GetScalarValueWithConnectionObject(pSQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValueWithConnectionObject(SqlCommand As String, SqlConnection As SqlConnection,
|
||||
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional Transaction As SqlTransaction = Nothing,
|
||||
Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Public Function GetScalarValueWithConnection(pSqlCommandObject As SqlCommand, pConnectionString As String, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Using oConnection = GetConnection(pConnectionString)
|
||||
Return GetScalarValueWithConnectionObject(pSqlCommandObject, oConnection, TransactionMode.WithTransaction, Nothing, pTimeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
||||
Public Function GetScalarValueWithConnectionObject(pSqlCommand As String, pSqlConnection As SqlConnection,
|
||||
Optional pTransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional pTransaction As SqlTransaction = Nothing,
|
||||
Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Dim oSQLCommand As New SqlCommand(pSqlCommand)
|
||||
Return GetScalarValueWithConnectionObject(oSQLCommand, pSqlConnection, pTransactionMode, pTransaction, pTimeout)
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValueWithConnectionObject(pSqlCommandObject As SqlCommand, pSqlConnection As SqlConnection,
|
||||
Optional pTransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional pTransaction As SqlTransaction = Nothing,
|
||||
Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
|
||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(pSqlConnection, pTransactionMode, pTransaction)
|
||||
Dim oResult As Object = Nothing
|
||||
|
||||
Try
|
||||
Using oSQLCOmmand = SqlConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = SqlCommand
|
||||
oSQLCOmmand.CommandTimeout = Timeout
|
||||
oSQLCOmmand.Transaction = oTransaction
|
||||
pSqlCommandObject.Connection = pSqlConnection
|
||||
pSqlCommandObject.CommandTimeout = pTimeout
|
||||
pSqlCommandObject.Transaction = oTransaction
|
||||
oResult = pSqlCommandObject.ExecuteScalar()
|
||||
|
||||
oResult = oSQLCOmmand.ExecuteScalar()
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", SqlCommand)
|
||||
Logger.Warn("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", pSqlCommandObject)
|
||||
|
||||
Finally
|
||||
MaybeCommitTransaction(oTransaction, TransactionMode)
|
||||
MaybeCommitTransaction(oTransaction, pTransactionMode)
|
||||
End Try
|
||||
|
||||
Return oResult
|
||||
End Function
|
||||
|
||||
Public Function GetScalarValue(SQLCommand As SqlCommand, OutputParameter As String, Timeout As Integer) As Object
|
||||
Public Function GetScalarValue(pSqlCommand As SqlCommand, pOutputParameter As String, Optional pTimeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Try
|
||||
If TestCanConnect() = False Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Logger.Debug("GetScalarValue: Running Query [{0}]", SQLCommand)
|
||||
Logger.Debug("GetScalarValue: Running Query [{0}]", pSqlCommand)
|
||||
|
||||
If SQLCommand.CommandText.Contains(" ") Then
|
||||
SQLCommand.CommandType = CommandType.Text
|
||||
If pSqlCommand.CommandText.Contains(" ") Then
|
||||
pSqlCommand.CommandType = CommandType.Text
|
||||
Else
|
||||
SQLCommand.CommandType = CommandType.StoredProcedure
|
||||
pSqlCommand.CommandType = CommandType.StoredProcedure
|
||||
End If
|
||||
|
||||
Using oConnection As SqlConnection = GetSQLConnection()
|
||||
|
||||
SQLCommand.Connection = oConnection
|
||||
SQLCommand.Parameters(OutputParameter).Direction = ParameterDirection.Output
|
||||
SQLCommand.CommandTimeout = Timeout
|
||||
SQLCommand.ExecuteNonQuery()
|
||||
pSqlCommand.Connection = oConnection
|
||||
pSqlCommand.Parameters(pOutputParameter).Direction = ParameterDirection.Output
|
||||
pSqlCommand.CommandTimeout = pTimeout
|
||||
pSqlCommand.ExecuteNonQuery()
|
||||
oConnection.Close()
|
||||
|
||||
Return SQLCommand.Parameters(OutputParameter).Value
|
||||
Return pSqlCommand.Parameters(pOutputParameter).Value
|
||||
End Using
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Logger.Warn($"GetScalarValue failed SQLCommand [{SQLCommand}]")
|
||||
Logger.Warn($"GetScalarValue failed SQLCommand [{pSqlCommand}]")
|
||||
|
||||
Return Nothing
|
||||
End Try
|
||||
@ -509,7 +596,6 @@ Public Class MSSQLServer
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Private Sub NewExecuteNonQueryAsync_Callback(ByVal result As IAsyncResult)
|
||||
Dim command As SqlCommand = CType(result.AsyncState, SqlCommand)
|
||||
Dim res = command.EndExecuteNonQuery(result)
|
||||
|
||||
@ -99,6 +99,7 @@
|
||||
<Compile Include="Dispatcher.vb" />
|
||||
<Compile Include="Exceptions.vb" />
|
||||
<Compile Include="Adapters\Firebird.vb" />
|
||||
<Compile Include="Helpers.vb" />
|
||||
<Compile Include="IDatabase.vb" />
|
||||
<Compile Include="Adapters\ODBC.vb" />
|
||||
<Compile Include="Adapters\Oracle.vb" />
|
||||
|
||||
10
Database/Helpers.vb
Normal file
10
Database/Helpers.vb
Normal file
@ -0,0 +1,10 @@
|
||||
Public Class Helpers
|
||||
|
||||
Public Shared Function MaybeEscapeSQLCommand(pSQLCommand As String) As String
|
||||
|
||||
|
||||
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
@ -1,4 +1,5 @@
|
||||
Imports System.Data.Common
|
||||
Imports System.Data.SqlClient
|
||||
|
||||
Public Interface IDatabase
|
||||
''' <summary>
|
||||
@ -7,8 +8,8 @@ Public Interface IDatabase
|
||||
Property DBInitialized As Boolean
|
||||
Property CurrentConnectionString As String
|
||||
|
||||
Function GetDatatable(SqlCommand As String, Timeout As Integer) As DataTable
|
||||
Function GetDatatable(SqlCommand As String) As DataTable
|
||||
Function GetDatatable(SqlCommand As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Function GetDatatable(SqlCommand As SqlCommand, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
|
||||
Function ExecuteNonQuery(SQLCommand As String, Timeout As Integer) As Boolean
|
||||
Function ExecuteNonQuery(SQLCommand As String) As Boolean
|
||||
|
||||
@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices
|
||||
<Assembly: AssemblyCompany("Digital Data")>
|
||||
<Assembly: AssemblyProduct("Modules.Database")>
|
||||
<Assembly: AssemblyCopyright("Copyright © 2022")>
|
||||
<Assembly: AssemblyTrademark("2.2.7.4")>
|
||||
<Assembly: AssemblyTrademark("2.2.7.5")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
|
||||
' übernehmen, indem Sie "*" eingeben:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("2.2.7.4")>
|
||||
<Assembly: AssemblyFileVersion("2.2.7.4")>
|
||||
<Assembly: AssemblyVersion("2.2.7.5")>
|
||||
<Assembly: AssemblyFileVersion("2.2.7.5")>
|
||||
|
||||
@ -37,6 +37,8 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "ZooFlow", "ZooFlow\ZooFlow.
|
||||
EndProject
|
||||
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Messaging", "Messaging\Messaging.vbproj", "{AF664D85-0A4B-4BAB-A2F8-83110C06553A}"
|
||||
EndProject
|
||||
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Database.Test", "Database.Test\Database.Test.vbproj", "{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -111,6 +113,10 @@ Global
|
||||
{AF664D85-0A4B-4BAB-A2F8-83110C06553A}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{AF664D85-0A4B-4BAB-A2F8-83110C06553A}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{AF664D85-0A4B-4BAB-A2F8-83110C06553A}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{91B4DFC0-543C-43A7-A9E0-6817DCA277EC}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@ -3,8 +3,8 @@
|
||||
Public Class Environment
|
||||
Public Property User As New State.UserState
|
||||
Public Property Settings As New State.SettingsState
|
||||
Public Property Service As State.ServiceState
|
||||
Public Property Service As New State.ServiceState
|
||||
Public Property Database As MSSQLServer
|
||||
Public Property DatabaseIDB As MSSQLServer
|
||||
Public Property Modules As Dictionary(Of String, State.ModuleState)
|
||||
Public Property Modules As New Dictionary(Of String, State.ModuleState)
|
||||
End Class
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user