|
|
|
|
@@ -264,78 +264,86 @@ 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 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
|
|
|
|
|
|
|
|
|
|
'<DebuggerStepThrough()>
|
|
|
|
|
Public Function GetDatatableWithConnection(SqlCommand As String, pConnectionString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
|
|
|
|
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 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
|
|
|
|
|
Using oConnection = GetSQLConnection()
|
|
|
|
|
Return ExecuteNonQueryWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, QueryTimeout)
|
|
|
|
|
End Using
|
|
|
|
|
End Function
|
|
|
|
|
|
|
|
|
|
'<DebuggerStepThrough()>
|
|
|
|
|
Public Function ExecuteNonQuery(SQLCommand As String, Timeout As Integer) As Boolean Implements IDatabase.ExecuteNonQuery
|
|
|
|
|
Using oConnection = GetSQLConnection()
|
|
|
|
|
Return ExecuteNonQueryWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
|
|
|
|
|