diff --git a/Modules.Database/MSSQLServer.vb b/Modules.Database/MSSQLServer.vb index 93742d74..fa4bb264 100644 --- a/Modules.Database/MSSQLServer.vb +++ b/Modules.Database/MSSQLServer.vb @@ -49,41 +49,41 @@ Public Class MSSQLServer Return oConnectionStringBuilder.ToString End Function - Public Function Get_ConnectionStringforID(pID As Integer) + Public Function Get_ConnectionStringforID(pConnectionId As Integer) Dim connectionString As String = "" Try - 'Me.TBCONNECTIONTableAdapter.FillByID(Me.DD_DMSLiteDataSet.TBCONNECTION, id) - Dim oDTConnection As DataTable = GetDatatable("SELECT * FROM TBDD_CONNECTION WHERE GUID = " & pID) + Dim oDTConnection As DataTable = GetDatatable($"SELECT * FROM TBDD_CONNECTION WHERE GUID = {pConnectionId}") If oDTConnection.Rows.Count = 1 Then - Select Case oDTConnection.Rows(0).Item("SQL_PROVIDER").ToString.ToUpper + Dim oRow As DataRow = oDTConnection.Rows(0) + Dim oProvider = oRow.Item("SQL_PROVIDER").ToString.ToUpper + Dim oServer = oRow.Item("SERVER") + Dim oDatabase = oRow.Item("DATENBANK") + Dim oUser = oRow.Item("USERNAME") + Dim oPassword = oRow.Item("PASSWORD") + + Select Case oProvider Case "MS-SQL" - If oDTConnection.Rows(0).Item("USERNAME") = "WINAUTH" Then - connectionString = "Server=" & oDTConnection.Rows(0).Item("SERVER") & ";Database=" & oDTConnection.Rows(0).Item("DATENBANK") & ";Trusted_Connection=True;" + If oUser = "WINAUTH" Then + connectionString = $"Server={oServer};Database={oDatabase};Trusted_Connection=True;" Else - connectionString = "Server=" & oDTConnection.Rows(0).Item("SERVER") & ";Database=" & oDTConnection.Rows(0).Item("DATENBANK") & ";User Id=" & oDTConnection.Rows(0).Item("USERNAME") & ";Password=" & oDTConnection.Rows(0).Item("USERNAME") & ";Password=" & oDTConnection.Rows(0).Item("PASSWORD") & ";" + connectionString = $"Server={oServer};Database={oDatabase};User Id={oUser};Password={oPassword};" End If - ' connectionString = "Server=" & DTConnection.Rows(0).Item("SERVER") & ";Database=" & DTConnection.Rows(0).Item("DATENBANK") & ";User Id=" & DTConnection.Rows(0).Item("USERNAME") & ";Password=" & DTConnection.Rows(0).Item("PASSWORD") & ";" Case "Oracle" - If oDTConnection.Rows(0).Item("BEMERKUNG").ToString.Contains("without tnsnames") Then - connectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" & oDTConnection.Rows(0).Item("SERVER") & ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" & - oDTConnection.Rows(0).Item("DATENBANK") & ")));User Id=" & oDTConnection.Rows(0).Item("USERNAME") & ";Password=" & oDTConnection.Rows(0).Item("PASSWORD") & ";" + If oRow.Item("BEMERKUNG").ToString.Contains("without tnsnames") Then + connectionString = $"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={oServer})(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME={oDatabase})));User Id={oUser};Password={oPassword};" Else - connectionString = "Data Source=" & oDTConnection.Rows(0).Item("SERVER") & ";Persist Security Info=True;User Id=" & oDTConnection.Rows(0).Item("USERNAME") & ";Password=" & oDTConnection.Rows(0).Item("PASSWORD") & ";Unicode=True" + connectionString = $"Data Source={oServer};Persist Security Info=True;User Id={oUser};Password={oPassword};Unicode=True" End If - 'Case "ODBC" - ' Dim conn As New OdbcConnection("dsn=" & DTConnection.Rows(0).Item("SERVER") & ";uid=" & DTConnection.Rows(0).Item("USERNAME") & ";pwd=" + DTConnection.Rows(0).Item("PASSWORD")) - ' connectionString = conn.ConnectionString Case Else - _Logger.Info(" - ConnectionType nicht integriert") + _Logger.Warn("Provider {0} nicht unterstützt!", oProvider) End Select Else - _Logger.Info(" No entry for Connection-ID: " & pID.ToString) + _Logger.Info("No entry for Connection-ID: " & pConnectionId.ToString) End If - Catch ex As Exception _Logger.Error(ex) - _Logger.Info(" - Error in bei Get ConnectionString - Fehler: " & vbNewLine & ex.Message) + _Logger.Info("Error in bei Get_ConnectionStringforID") End Try Return connectionString End Function @@ -94,6 +94,7 @@ Public Class MSSQLServer Private Function TestCanConnect(ConnectionString As String) As Boolean Try + _Logger.Debug("Testing connection to [{0}]", ConnectionString) Dim oConnection As New SqlConnection(ConnectionString) oConnection.Open() oConnection.Close() diff --git a/Modules.Database/My Project/AssemblyInfo.vb b/Modules.Database/My Project/AssemblyInfo.vb index 52c637a4..f72c85a8 100644 --- a/Modules.Database/My Project/AssemblyInfo.vb +++ b/Modules.Database/My Project/AssemblyInfo.vb @@ -12,7 +12,7 @@ Imports System.Runtime.InteropServices - + @@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices ' übernehmen, indem Sie "*" eingeben: ' - - + +