Database: Fix connection string error
This commit is contained in:
parent
1632e86c1e
commit
711d0edd04
@ -9,7 +9,7 @@ Public Class MSSQLServer
|
||||
Implements IDatabase
|
||||
|
||||
Public Property DBInitialized As Boolean = False Implements IDatabase.DBInitialized
|
||||
Public Property ConnectionString As String = "" Implements IDatabase.ConnectionString
|
||||
Public Property CurrentConnectionString As String = "" Implements IDatabase.CurrentConnectionString
|
||||
|
||||
Private ReadOnly QueryTimeout As Integer
|
||||
Private ReadOnly Logger As Logger
|
||||
@ -28,8 +28,8 @@ Public Class MSSQLServer
|
||||
QueryTimeout = pTimeout
|
||||
|
||||
Try
|
||||
DBInitialized = TestCanConnect()
|
||||
ConnectionString = pConnectionString
|
||||
CurrentConnectionString = pConnectionString
|
||||
DBInitialized = TestCanConnect(CurrentConnectionString)
|
||||
Catch ex As Exception
|
||||
DBInitialized = False
|
||||
Logger.Error(ex)
|
||||
@ -41,8 +41,8 @@ Public Class MSSQLServer
|
||||
QueryTimeout = Timeout
|
||||
|
||||
Try
|
||||
DBInitialized = TestCanConnect()
|
||||
ConnectionString = GetConnectionString(Server, Database, UserId, Password)
|
||||
CurrentConnectionString = GetConnectionString(Server, Database, UserId, Password)
|
||||
DBInitialized = TestCanConnect(CurrentConnectionString)
|
||||
Catch ex As Exception
|
||||
DBInitialized = False
|
||||
Logger.Error(ex)
|
||||
@ -52,12 +52,12 @@ Public Class MSSQLServer
|
||||
''' <summary>
|
||||
''' Encrypts a connection string password.
|
||||
''' </summary>
|
||||
''' <param name="ConnectionString">A connection string with a plain-text password</param>
|
||||
''' <param name="pConnectionString">A connection string with a plain-text password</param>
|
||||
''' <returns>The connection string with the password encrypted.</returns>
|
||||
<DebuggerStepThrough()>
|
||||
Public Shared Function EncryptConnectionString(ConnectionString As String) As String
|
||||
Public Shared Function EncryptConnectionString(pConnectionString As String) As String
|
||||
Dim oEncryption As New EncryptionLegacy()
|
||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = ConnectionString}
|
||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = pConnectionString}
|
||||
Dim oEncryptedPassword = oEncryption.EncryptData(oBuilder.Password)
|
||||
oBuilder.Password = oEncryptedPassword
|
||||
|
||||
@ -67,12 +67,12 @@ Public Class MSSQLServer
|
||||
''' <summary>
|
||||
''' Decrypts a connection string password.
|
||||
''' </summary>
|
||||
''' <param name="ConnectionString">A connection string with a encrypted password</param>
|
||||
''' <param name="pConnectionString">A connection string with a encrypted password</param>
|
||||
''' <returns>The connection string with the password decrypted.</returns>
|
||||
<DebuggerStepThrough()>
|
||||
Public Shared Function DecryptConnectionString(ConnectionString As String) As String
|
||||
Public Shared Function DecryptConnectionString(pConnectionString As String) As String
|
||||
Dim oEncryption As New EncryptionLegacy()
|
||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = ConnectionString}
|
||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = pConnectionString}
|
||||
Dim oDecryptedPassword = oEncryption.DecryptData(oBuilder.Password)
|
||||
oBuilder.Password = oDecryptedPassword
|
||||
|
||||
@ -195,14 +195,14 @@ Public Class MSSQLServer
|
||||
|
||||
<DebuggerStepThrough()>
|
||||
Private Function TestCanConnect() As Boolean
|
||||
Return TestCanConnect(ConnectionString)
|
||||
Return TestCanConnect(CurrentConnectionString)
|
||||
End Function
|
||||
|
||||
Private Function TestCanConnect(ConnectionString As String) As Boolean
|
||||
Private Function TestCanConnect(pConnectionString As String) As Boolean
|
||||
Try
|
||||
Logger.Debug("Testing connection to [{0}]", MaskConnectionString(ConnectionString))
|
||||
Logger.Debug("Testing connection to [{0}]", MaskConnectionString(pConnectionString))
|
||||
|
||||
Dim oDecryptedConnectionString = DecryptConnectionString(ConnectionString)
|
||||
Dim oDecryptedConnectionString = DecryptConnectionString(pConnectionString)
|
||||
Dim oConnection As New SqlConnection(oDecryptedConnectionString)
|
||||
OpenSQLConnection(oConnection)
|
||||
oConnection.Close()
|
||||
@ -213,24 +213,6 @@ Public Class MSSQLServer
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function TestCanConnect(Connection As SqlConnection) As Boolean
|
||||
Try
|
||||
If Connection Is Nothing Then
|
||||
Logger.Warn("TestCanConnect: Connection is nothing!")
|
||||
Return False
|
||||
End If
|
||||
|
||||
Logger.Debug("Testing connection to [{0}]", MaskConnectionString(Connection.ConnectionString))
|
||||
|
||||
OpenSQLConnection(Connection)
|
||||
Connection.Close()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' This Function intentionally has no try..catch block to have any errors caught outside
|
||||
''' </summary>
|
||||
@ -246,15 +228,15 @@ Public Class MSSQLServer
|
||||
|
||||
<DebuggerStepThrough()>
|
||||
Private Function GetSQLConnection() As SqlConnection
|
||||
Return GetConnection(ConnectionString)
|
||||
Return GetConnection(CurrentConnectionString)
|
||||
End Function
|
||||
|
||||
Private Function GetConnection(ConnectionString As String) As SqlConnection
|
||||
Private Function GetConnection(pConnectionString As String) As SqlConnection
|
||||
Try
|
||||
Dim oConnection As New SqlConnection(ConnectionString)
|
||||
Dim oConnection As New SqlConnection(pConnectionString)
|
||||
oConnection = OpenSQLConnection(oConnection)
|
||||
|
||||
Dim oMaskedConnectionString = MaskConnectionString(ConnectionString)
|
||||
Dim oMaskedConnectionString = MaskConnectionString(pConnectionString)
|
||||
Logger.Debug("The Following Connection is open: {0}", oMaskedConnectionString)
|
||||
|
||||
Return oConnection
|
||||
@ -266,14 +248,15 @@ Public Class MSSQLServer
|
||||
End Function
|
||||
|
||||
<DebuggerStepThrough()>
|
||||
Private Function MaskConnectionString(ConnectionString As String) As String
|
||||
Private Function MaskConnectionString(pConnectionString As String) As String
|
||||
Try
|
||||
If ConnectionString Is Nothing OrElse ConnectionString.Length = 0 Then
|
||||
Throw New ArgumentNullException("ConnectionString")
|
||||
If pConnectionString Is Nothing OrElse pConnectionString.Length = 0 Then
|
||||
Logger.Warn("Connection String is empty!")
|
||||
Throw New ArgumentNullException("pConnectionString")
|
||||
End If
|
||||
|
||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = ConnectionString}
|
||||
Dim oConnectionString = ConnectionString.Replace(oBuilder.Password, "XXXXX")
|
||||
Dim oBuilder As New SqlConnectionStringBuilder() With {.ConnectionString = pConnectionString}
|
||||
Dim oConnectionString = pConnectionString.Replace(oBuilder.Password, "XXXXX")
|
||||
Return oConnectionString
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
@ -310,8 +293,8 @@ Public Class MSSQLServer
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetDatatableWithConnection(SqlCommand As String, ConnectionString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Using oConnection = GetConnection(ConnectionString)
|
||||
Public Function GetDatatableWithConnection(SqlCommand As String, pConnectionString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As DataTable
|
||||
Using oConnection = GetConnection(pConnectionString)
|
||||
Return GetDatatableWithConnectionObject(SqlCommand, oConnection, Timeout:=Timeout)
|
||||
End Using
|
||||
End Function
|
||||
@ -431,8 +414,8 @@ Public Class MSSQLServer
|
||||
End Function
|
||||
|
||||
'<DebuggerStepThrough()>
|
||||
Public Function GetScalarValueWithConnection(SQLCommand As String, ConnectionString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Using oConnection = GetConnection(ConnectionString)
|
||||
Public Function GetScalarValueWithConnection(SQLCommand As String, pConnectionString As String, Optional Timeout As Integer = Constants.DEFAULT_TIMEOUT) As Object
|
||||
Using oConnection = GetConnection(pConnectionString)
|
||||
Return GetScalarValueWithConnectionObject(SQLCommand, oConnection, TransactionMode.WithTransaction, Nothing, Timeout)
|
||||
End Using
|
||||
End Function
|
||||
|
||||
@ -6,7 +6,7 @@ Public Class Oracle
|
||||
Implements IDatabase
|
||||
|
||||
Public Property DBInitialized As Boolean = False Implements IDatabase.DBInitialized
|
||||
Public Property ConnectionString As String = "" Implements IDatabase.ConnectionString
|
||||
Public Property CurrentConnectionString As String = "" Implements IDatabase.CurrentConnectionString
|
||||
|
||||
Private ReadOnly _Timeout As Integer
|
||||
Private ReadOnly _Logger As Logger
|
||||
@ -23,8 +23,8 @@ Public Class Oracle
|
||||
_Timeout = Timeout
|
||||
_Logger = LogConfig.GetLogger()
|
||||
|
||||
ConnectionString = GetConnectionString(Server, Database, UserId, Password)
|
||||
DBInitialized = TestCanConnect(ConnectionString)
|
||||
CurrentConnectionString = GetConnectionString(Server, Database, UserId, Password)
|
||||
DBInitialized = TestCanConnect(CurrentConnectionString)
|
||||
End Sub
|
||||
|
||||
Private Function TestCanConnect(ConnectionString As String) As Boolean
|
||||
@ -85,7 +85,7 @@ Public Class Oracle
|
||||
Try
|
||||
Dim oSQLconnect As New OracleConnection
|
||||
Dim oSQLCOmmand As OracleCommand
|
||||
oSQLconnect.ConnectionString = ConnectionString
|
||||
oSQLconnect.ConnectionString = CurrentConnectionString
|
||||
oSQLconnect.Open()
|
||||
oSQLCOmmand = oSQLconnect.CreateCommand()
|
||||
oSQLCOmmand.CommandText = executeStatement
|
||||
@ -111,7 +111,7 @@ Public Class Oracle
|
||||
Try
|
||||
Dim oSQLconnect As New OracleConnection
|
||||
Dim oSQLCOmmand As OracleCommand
|
||||
oSQLconnect.ConnectionString = ConnectionString
|
||||
oSQLconnect.ConnectionString = CurrentConnectionString
|
||||
oSQLconnect.Open()
|
||||
oSQLCOmmand = oSQLconnect.CreateCommand()
|
||||
oSQLCOmmand.CommandText = executeStatement
|
||||
@ -129,7 +129,7 @@ Public Class Oracle
|
||||
|
||||
Public Function GetDatatable(pSQLCommand As String, pTimeout As Integer) As DataTable Implements IDatabase.GetDatatable
|
||||
Try
|
||||
Using oConnection = GetConnection(ConnectionString)
|
||||
Using oConnection = GetConnection(CurrentConnectionString)
|
||||
Dim oSQLCommand As OracleCommand
|
||||
oSQLCommand = oConnection.CreateCommand()
|
||||
oSQLCommand.CommandText = pSQLCommand
|
||||
@ -157,7 +157,7 @@ Public Class Oracle
|
||||
|
||||
Public Function ExecuteNonQuery(pSQLCommand As String, pTimeout As Integer) As Boolean Implements IDatabase.ExecuteNonQuery
|
||||
Try
|
||||
Using oConnection = GetConnection(ConnectionString)
|
||||
Using oConnection = GetConnection(CurrentConnectionString)
|
||||
Dim oSQLCOmmand As OracleCommand
|
||||
oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = pSQLCommand
|
||||
@ -183,7 +183,7 @@ Public Class Oracle
|
||||
Public Function GetScalarValue(pSQLCommand As String, pTimeout As Integer) As Object Implements IDatabase.GetScalarValue
|
||||
Dim result
|
||||
Try
|
||||
Using oConnection = GetConnection(ConnectionString)
|
||||
Using oConnection = GetConnection(CurrentConnectionString)
|
||||
Dim oSQLCOmmand As OracleCommand
|
||||
oSQLCOmmand = oConnection.CreateCommand()
|
||||
oSQLCOmmand.CommandText = pSQLCommand
|
||||
|
||||
@ -5,7 +5,7 @@ Public Interface IDatabase
|
||||
''' Returns true if the initial connection to the configured database was successful.
|
||||
''' </summary>
|
||||
Property DBInitialized As Boolean
|
||||
Property ConnectionString As String
|
||||
Property CurrentConnectionString As String
|
||||
|
||||
Function GetDatatable(SqlCommand As String, Timeout As Integer) As DataTable
|
||||
Function GetDatatable(SqlCommand As String) As DataTable
|
||||
|
||||
@ -156,8 +156,8 @@ Public Class GlobalState
|
||||
_Logger.Debug("ForceDirectDatabaseAccess: {0}", pConfig.ClientConfig.ForceDirectDatabaseAccess)
|
||||
ClientConfig.ForceDirectDatabaseAccess = pConfig.ClientConfig.ForceDirectDatabaseAccess
|
||||
ClientConfig.DocumentTypes = Doctypes
|
||||
ClientConfig.ConnectionStringECM = _MSSQL_ECM.ConnectionString
|
||||
ClientConfig.ConnectionStringIDB = _MSSQL_IDB.ConnectionString
|
||||
ClientConfig.ConnectionStringECM = _MSSQL_ECM.CurrentConnectionString
|
||||
ClientConfig.ConnectionStringIDB = _MSSQL_IDB.CurrentConnectionString
|
||||
End Sub
|
||||
|
||||
Public Class ObjectStore
|
||||
|
||||
@ -30,7 +30,7 @@ namespace ZUGFeRDRESTService
|
||||
MSSQL = new MSSQLServer(LogConfig, AppConfig["MSSQLConnectionString"]);
|
||||
Firebird = new Firebird(LogConfig, FBConfig["Datasource"], FBConfig["Database"], FBConfig["Username"], FBConfig["Password"]);
|
||||
|
||||
Logger.Debug("MSSQL Connection: [{0}]", MSSQL.ConnectionString);
|
||||
Logger.Debug("MSSQL Connection: [{0}]", MSSQL.CurrentConnectionString);
|
||||
Logger.Debug("Firebird Connection: [{0}]", Firebird.ConnectionString);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user