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
|
||||
|
||||
_Logger.Debug("Testing connection to [{0}]", MaskConnectionString(Connection.ConnectionString))
|
||||
|
||||
If Connection.State = ConnectionState.Closed Then
|
||||
Connection.Open()
|
||||
End If
|
||||
|
||||
Connection.Close()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
@ -199,6 +203,10 @@ Public Class MSSQLServer
|
||||
|
||||
Private Function MaskConnectionString(ConnectionString As String) As String
|
||||
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 oConnectionString = ConnectionString.Replace(oBuilder.Password, "XXXXX")
|
||||
Return oConnectionString
|
||||
@ -229,7 +237,6 @@ Public Class MSSQLServer
|
||||
End Using
|
||||
End Function
|
||||
|
||||
|
||||
Public Async Function GetDatatableAsync(SqlCommand As String) As Task(Of DataTable)
|
||||
Return Await Task.Run(Function() GetDatatable(SqlCommand, _Timeout))
|
||||
End Function
|
||||
@ -244,10 +251,6 @@ Public Class MSSQLServer
|
||||
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional Transaction As SqlTransaction = Nothing,
|
||||
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 oTable As New DataTable() With {.TableName = TABLE_DEFAULT}
|
||||
|
||||
@ -262,8 +265,6 @@ Public Class MSSQLServer
|
||||
_Logger.Debug("GetDatatableWithConnectionObject: Running Query [{0}]", SqlCommand)
|
||||
|
||||
oAdapter.Fill(oTable)
|
||||
|
||||
_Logger.Debug("GetDatatableWithConnectionObject: Running Query [{0}]", SqlCommand)
|
||||
Catch ex As Exception
|
||||
_Logger.Error(ex)
|
||||
_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 Transaction As SqlTransaction = Nothing,
|
||||
Optional Timeout As Integer = 120) As Boolean
|
||||
If TestCanConnect(SqlConnection) = False Then
|
||||
Return False
|
||||
End If
|
||||
|
||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
||||
|
||||
Try
|
||||
@ -365,9 +362,6 @@ Public Class MSSQLServer
|
||||
Optional TransactionMode As TransactionMode = TransactionMode.WithTransaction,
|
||||
Optional Transaction As SqlTransaction = Nothing,
|
||||
Optional Timeout As Integer = 120) As Object
|
||||
If TestCanConnect() = False Then
|
||||
Return Nothing
|
||||
End If
|
||||
|
||||
Dim oTransaction As SqlTransaction = MaybeGetTransaction(SqlConnection, TransactionMode, Transaction)
|
||||
Dim oResult As Object = Nothing
|
||||
@ -433,10 +427,6 @@ Public Class MSSQLServer
|
||||
''' <param name="commandtimeout">Optional Timeout</param>
|
||||
''' <remarks></remarks>
|
||||
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)
|
||||
|
||||
Try
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user