Database: Remove TestCanConnect for most functions, check connection state for TestCanConnect, check for empty connection string in maskconnectionstring
This commit is contained in:
parent
d17ef894a0
commit
a45b8db100
@ -168,7 +168,11 @@ Public Class MSSQLServer
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
_Logger.Debug("Testing connection to [{0}]", MaskConnectionString(Connection.ConnectionString))
|
_Logger.Debug("Testing connection to [{0}]", MaskConnectionString(Connection.ConnectionString))
|
||||||
Connection.Open()
|
|
||||||
|
If Connection.State = ConnectionState.Closed Then
|
||||||
|
Connection.Open()
|
||||||
|
End If
|
||||||
|
|
||||||
Connection.Close()
|
Connection.Close()
|
||||||
Return True
|
Return True
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
@ -199,6 +203,10 @@ Public Class MSSQLServer
|
|||||||
|
|
||||||
Private Function MaskConnectionString(ConnectionString As String) As String
|
Private Function MaskConnectionString(ConnectionString As String) As String
|
||||||
Try
|
Try
|
||||||
|
If ConnectionString Is Nothing OrElse ConnectionString.Length = 0 Then
|
||||||
|
Throw New ArgumentNullException("ConnectionString")
|
||||||
|
End If
|
||||||
|
|
||||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = ConnectionString}
|
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = ConnectionString}
|
||||||
Dim oConnectionString = ConnectionString.Replace(oBuilder.Password, "XXXXX")
|
Dim oConnectionString = ConnectionString.Replace(oBuilder.Password, "XXXXX")
|
||||||
Return oConnectionString
|
Return oConnectionString
|
||||||
@ -229,7 +237,6 @@ Public Class MSSQLServer
|
|||||||
End Using
|
End Using
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
Public Async Function GetDatatableAsync(SqlCommand As String) As Task(Of DataTable)
|
Public Async Function GetDatatableAsync(SqlCommand As String) As Task(Of DataTable)
|
||||||
Return Await Task.Run(Function() GetDatatable(SqlCommand, _Timeout))
|
Return Await Task.Run(Function() GetDatatable(SqlCommand, _Timeout))
|
||||||
End Function
|
End Function
|
||||||
@ -244,10 +251,6 @@ Public Class MSSQLServer
|
|||||||
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||||
Optional Transaction As SqlTransaction = Nothing,
|
Optional Transaction As SqlTransaction = Nothing,
|
||||||
Optional Timeout As Integer = 120) As DataTable
|
Optional Timeout As Integer = 120) As DataTable
|
||||||
If TestCanConnect(SqlConnection) = False Then
|
|
||||||
Return Nothing
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
||||||
Dim oTable As New DataTable() With {.TableName = TABLE_DEFAULT}
|
Dim oTable As New DataTable() With {.TableName = TABLE_DEFAULT}
|
||||||
|
|
||||||
@ -262,8 +265,6 @@ Public Class MSSQLServer
|
|||||||
_Logger.Debug("GetDatatableWithConnectionObject: Running Query [{0}]", SqlCommand)
|
_Logger.Debug("GetDatatableWithConnectionObject: Running Query [{0}]", SqlCommand)
|
||||||
|
|
||||||
oAdapter.Fill(oTable)
|
oAdapter.Fill(oTable)
|
||||||
|
|
||||||
_Logger.Debug("GetDatatableWithConnectionObject: Running Query [{0}]", SqlCommand)
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_Logger.Error(ex)
|
_Logger.Error(ex)
|
||||||
_Logger.Warn("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", SqlCommand)
|
_Logger.Warn("GetDatatableWithConnectionObject: Error in GetDatatableWithConnection while executing command: [{0}]", SqlCommand)
|
||||||
@ -308,10 +309,6 @@ Public Class MSSQLServer
|
|||||||
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||||
Optional Transaction As SqlTransaction = Nothing,
|
Optional Transaction As SqlTransaction = Nothing,
|
||||||
Optional Timeout As Integer = 120) As Boolean
|
Optional Timeout As Integer = 120) As Boolean
|
||||||
If TestCanConnect(SqlConnection) = False Then
|
|
||||||
Return False
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
||||||
|
|
||||||
Try
|
Try
|
||||||
@ -365,9 +362,6 @@ Public Class MSSQLServer
|
|||||||
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||||
Optional Transaction As SqlTransaction = Nothing,
|
Optional Transaction As SqlTransaction = Nothing,
|
||||||
Optional Timeout As Integer = 120) As Object
|
Optional Timeout As Integer = 120) As Object
|
||||||
If TestCanConnect() = False Then
|
|
||||||
Return Nothing
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
||||||
Dim oResult As Object = Nothing
|
Dim oResult As Object = Nothing
|
||||||
@ -433,10 +427,6 @@ Public Class MSSQLServer
|
|||||||
''' <param name="commandtimeout">Optional Timeout</param>
|
''' <param name="commandtimeout">Optional Timeout</param>
|
||||||
''' <remarks></remarks>
|
''' <remarks></remarks>
|
||||||
Public Sub NewExecuteNonQueryAsync(SqlCommand As String, Optional commandtimeout As Integer = 120)
|
Public Sub NewExecuteNonQueryAsync(SqlCommand As String, Optional commandtimeout As Integer = 120)
|
||||||
If TestCanConnect() = False Then
|
|
||||||
Exit Sub
|
|
||||||
End If
|
|
||||||
|
|
||||||
_Logger.Debug("NewExecuteNonQueryAsync: Running Query [{0}]", SqlCommand)
|
_Logger.Debug("NewExecuteNonQueryAsync: Running Query [{0}]", SqlCommand)
|
||||||
|
|
||||||
Try
|
Try
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user