Remove ClassFormFunctions, switch to Database Module for getting connection string from connection id
This commit is contained in:
@@ -23,54 +23,6 @@ Public Class ClassDatabase
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Shared Function Get_ConnectionString(id As Integer)
|
||||
Dim connectionString As String = ""
|
||||
Try
|
||||
'Me.TBCONNECTIONTableAdapter.FillByID(Me.DD_DMSLiteDataSet.TBCONNECTION, id)
|
||||
Dim DTConnection As DataTable = ClassDatabase.Return_Datatable("SELECT * FROM TBDD_CONNECTION WHERE GUID = " & id)
|
||||
If DTConnection.Rows.Count = 1 Then
|
||||
Select Case DTConnection.Rows(0).Item("SQL_PROVIDER").ToString.ToUpper
|
||||
Case "MS-SQL"
|
||||
If DTConnection.Rows(0).Item("USERNAME") = "WINAUTH" Then
|
||||
connectionString = "Server=" & DTConnection.Rows(0).Item("SERVER") & ";Database=" & DTConnection.Rows(0).Item("DATENBANK") & ";Trusted_Connection=True;"
|
||||
Else
|
||||
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("USERNAME") & ";Password=" & DTConnection.Rows(0).Item("PASSWORD") & ";"
|
||||
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 DTConnection.Rows(0).Item("BEMERKUNG").ToString.Contains("without tnsnames") Then
|
||||
connectionString = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" & DTConnection.Rows(0).Item("SERVER") & ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" &
|
||||
DTConnection.Rows(0).Item("DATENBANK") & ")));User Id=" & DTConnection.Rows(0).Item("USERNAME") & ";Password=" & DTConnection.Rows(0).Item("PASSWORD") & ";"
|
||||
Else
|
||||
connectionString = "Data Source=" & DTConnection.Rows(0).Item("SERVER") & ";Persist Security Info=True;User Id=" & DTConnection.Rows(0).Item("USERNAME") & ";Password=" & DTConnection.Rows(0).Item("PASSWORD") & ";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")
|
||||
MsgBox("ConnectionType nicht integriert", MsgBoxStyle.Critical, "Bitte Konfiguration Connection überprüfen!")
|
||||
End Select
|
||||
Else
|
||||
LOGGER.Info(" No entry for Connection-ID: " & id.ToString)
|
||||
End If
|
||||
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Info(" - Error in bei Get ConnectionString - Fehler: " & vbNewLine & ex.Message)
|
||||
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error in Get ConnectionString:")
|
||||
End Try
|
||||
Return connectionString
|
||||
End Function
|
||||
|
||||
Public Shared Function Return_Datatable_Combined(SqlCommand As String, ConnectionString As String, Optional userInput As Boolean = False)
|
||||
If ConnectionString.Contains("Initial Catalog=") Then
|
||||
Return Return_Datatable_CS(SqlCommand, ConnectionString, userInput)
|
||||
Else
|
||||
Return Oracle_Return_Datatable(SqlCommand, ConnectionString, userInput)
|
||||
End If
|
||||
End Function
|
||||
|
||||
Public Shared Function Return_Datatable(sql_command As String, Optional userInput As Boolean = False) As DataTable
|
||||
Try
|
||||
Dim SQLconnect As New SqlConnection
|
||||
@@ -148,110 +100,7 @@ Public Class ClassDatabase
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
Public Shared Function Execute_non_Query(sql_command As String, Optional userInput As Boolean = False) As Boolean
|
||||
Try
|
||||
Dim SQLconnect As New SqlConnection
|
||||
Dim SQLcommand As SqlCommand
|
||||
SQLconnect.ConnectionString = SQLSERVERConnectionString
|
||||
SQLconnect.Open()
|
||||
SQLcommand = SQLconnect.CreateCommand
|
||||
'Update Last Created Record in Foo
|
||||
SQLcommand.CommandText = sql_command
|
||||
SQLcommand.ExecuteNonQuery()
|
||||
SQLcommand.Dispose()
|
||||
SQLconnect.Close()
|
||||
|
||||
' Reset timeout counter when query was sucessful
|
||||
DatabaseConnectionTimeout = False
|
||||
|
||||
Return True
|
||||
Catch ex As SqlException
|
||||
Dim handled = CatchDatabaseTimeout(ex, sql_command)
|
||||
|
||||
If Not handled Then
|
||||
If userInput = True Then
|
||||
MsgBox("Error in Execute non query - Error-Message:" & vbNewLine & ex.Message & vbNewLine & "SQL-Command:" & vbNewLine & sql_command, MsgBoxStyle.Critical)
|
||||
End If
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Info("#SQL: " & sql_command)
|
||||
End If
|
||||
|
||||
Return False
|
||||
Catch ex As Exception
|
||||
If userInput = True Then
|
||||
MsgBox("Error in Execute non query - Error-Message:" & vbNewLine & ex.Message & vbNewLine & "SQL-Command:" & vbNewLine & sql_command, MsgBoxStyle.Critical)
|
||||
End If
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Info("#SQL: " & sql_command)
|
||||
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Public Shared Function Execute_non_Query_ConStr(ExecuteCMD As String, ConnString As String, Optional userInput As Boolean = False)
|
||||
Try
|
||||
Dim SQLconnect As New SqlClient.SqlConnection
|
||||
Dim SQLcommand As SqlClient.SqlCommand
|
||||
SQLconnect.ConnectionString = ConnString
|
||||
SQLconnect.Open()
|
||||
SQLcommand = SQLconnect.CreateCommand
|
||||
'Update Last Created Record in Foo
|
||||
SQLcommand.CommandText = ExecuteCMD
|
||||
LOGGER.Debug("Execute_non_Query_ConStr Created: " & ExecuteCMD)
|
||||
SQLcommand.ExecuteNonQuery()
|
||||
SQLcommand.Dispose()
|
||||
SQLconnect.Close()
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
LOGGER.Error(ex)
|
||||
If userInput = True Then
|
||||
MsgBox("Error in Execute_non_Query_ConStr - Error-Message:" & vbNewLine & ex.Message & vbNewLine & "SQL-Command:" & vbNewLine & ExecuteCMD, MsgBoxStyle.Critical)
|
||||
End If
|
||||
Clipboard.SetText("Error Execute_non_Query_ConStr: " & ex.Message & vbNewLine & "SQL: " & ExecuteCMD)
|
||||
LOGGER.Info("Fehler bei Execute_non_Query_ConStr: " & ex.Message, True)
|
||||
LOGGER.Info("#SQL: " & ExecuteCMD, False)
|
||||
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Public Shared Function Execute_Scalar(sql_command As String, ConString As String, Optional userInput As Boolean = False)
|
||||
Dim result
|
||||
Try
|
||||
Dim SQLconnect As New SqlConnection
|
||||
Dim SQLcommand As SqlCommand
|
||||
SQLconnect.ConnectionString = ConString
|
||||
SQLconnect.Open()
|
||||
SQLcommand = SQLconnect.CreateCommand
|
||||
'Update Last Created Record in Foo
|
||||
SQLcommand.CommandText = sql_command
|
||||
result = SQLcommand.ExecuteScalar()
|
||||
SQLcommand.Dispose()
|
||||
SQLconnect.Close()
|
||||
|
||||
' Reset timeout counter when query was sucessful
|
||||
DatabaseConnectionTimeout = False
|
||||
|
||||
Return result
|
||||
Catch ex As SqlException
|
||||
Dim handled = CatchDatabaseTimeout(ex, sql_command)
|
||||
|
||||
If Not handled Then
|
||||
If userInput = True Then
|
||||
MsgBox("Error in Execute non query - Error-Message:" & vbNewLine & ex.Message & vbNewLine & "SQL-Command:" & vbNewLine & sql_command, MsgBoxStyle.Critical)
|
||||
End If
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Info("#SQL: " & sql_command)
|
||||
End If
|
||||
|
||||
Return False
|
||||
Catch ex As Exception
|
||||
If userInput = True Then
|
||||
MsgBox("Error in Execute Scalar - Error-Message:" & vbNewLine & ex.Message & vbNewLine & "SQL-Command:" & vbNewLine & sql_command, MsgBoxStyle.Critical)
|
||||
End If
|
||||
LOGGER.Error(ex)
|
||||
LOGGER.Info("#SQL: " & sql_command)
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
Public Shared Function OracleExecute_Scalar(cmdscalar As String, OracleConnection As String)
|
||||
Dim result
|
||||
Try
|
||||
|
||||
Reference in New Issue
Block a user