|
|
|
|
@@ -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)
|
|
|
|
|
|