Remove ClassFormFunctions, switch to Database Module for getting connection string from connection id

This commit is contained in:
Jonathan Jenne 2021-09-23 12:08:53 +02:00
parent 66039f22d8
commit d31ba427e2
9 changed files with 11 additions and 252 deletions

View File

@ -229,7 +229,7 @@ Public Class ClassControls
Dim cmb As ComboBox = ctrl
Dim sql As String = sql_result.ToString.ToUpper.Replace("@" & SearchString.ToUpper, Resultvalue)
connectionString = ClassFormFunctions.GetConnectionString(conid)
connectionString = DATABASE_ECM.Get_ConnectionStringforID(conid)
If connectionString Is Nothing = False Then
'SQL Befehl füllt die Auswahlliste
@ -436,7 +436,7 @@ Public Class ClassControls
Exit Sub
End If
Dim oConnectionString = ClassFormFunctions.GetConnectionString(SqlConnectionId)
Dim oConnectionString = DATABASE_ECM.Get_ConnectionStringforID(SqlConnectionId)
Dim oDatatable As DataTable = DATABASE_ECM.GetDatatable(SqlCommand)
Dim oFoundControl As Control = Nothing

View File

@ -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

View File

@ -1,74 +0,0 @@
Imports System.Text.RegularExpressions
Public Class ClassFormFunctions
Public Shared Function GetConnectionString(id As Integer)
Dim connectionString As String = ""
Try
'Me.TBCONNECTIONTableAdapter.FillByID(Me.DD_DMSLiteDataSet.TBCONNECTION, id)
Dim DTConnection As DataTable = DATABASE_ECM.GetDatatable("SELECT * FROM TBDD_CONNECTION WHERE GUID = " & id)
If DTConnection.Rows.Count = 1 Then
Dim CSType = DTConnection.Rows(0).Item("SQL_PROVIDER").ToString.ToUpper
Select Case CSType
Case "MS-SQL".ToUpper
If DTConnection.Rows(0).Item("USERNAME").ToString.ToLower = "winauth" Then
connectionString = "Data Source=" & DTConnection.Rows(0).Item("SERVER") & ";Initial Catalog= " & DTConnection.Rows(0).Item("DATENBANK") & ";Trusted_Connection=True;"
Else
connectionString = "Data Source=" & DTConnection.Rows(0).Item("SERVER") & ";Initial Catalog= " & DTConnection.Rows(0).Item("DATENBANK") & ";User Id=" & DTConnection.Rows(0).Item("USERNAME") & ";Password=" & DTConnection.Rows(0).Item("PASSWORD") & ";"
End If
Case "MS-SQLServer".ToUpper
If DTConnection.Rows(0).Item("USERNAME").ToString.ToLower = "winauth" Then
connectionString = "Data Source=" & DTConnection.Rows(0).Item("SERVER") & ";Initial Catalog= " & DTConnection.Rows(0).Item("DATENBANK") & ";Trusted_Connection=True;"
Else
connectionString = "Data Source=" & DTConnection.Rows(0).Item("SERVER") & ";Initial Catalog= " & DTConnection.Rows(0).Item("DATENBANK") & ";User Id=" & DTConnection.Rows(0).Item("USERNAME") & ";Password=" & DTConnection.Rows(0).Item("PASSWORD") & ";"
End If
Case "Oracle".ToUpper
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
'Dim conn As New OracleConnectionStringBuilder
'If chkOR_ohne_TNS.Checked Then
' connstr = "Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=" & SERVERTextBox.Text & ")(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" & _
' DATENBANKTextBox.Text & ")));User Id=" & USERNAMETextBox.Text & ";Password=" & PASSWORDTextBox.Text & ";"
'Else
' conn.DataSource = DATENBANKTextBox.Text
' conn.UserID = USERNAMETextBox.Text
' conn.Password = PASSWORDTextBox.Text
' conn.PersistSecurityInfo = True
' conn.ConnectionTimeout = 120
' connstr = conn.ConnectionString
'End If
'Data Source=MyOracleDB;User Id=myUsername;Password=myPassword;Integrated Security=no;
Case Else
LOGGER.Info(" - ConnectionType not integrated")
MsgBox("ConnectionType not integrated", MsgBoxStyle.Critical, "Please check connection:")
End Select
End If
Catch ex As Exception
LOGGER.Info(" - Unexpected Error in GetConnectionString:" & vbNewLine & ex.Message)
LOGGER.Error(ex)
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error in GetConnectionString:")
End Try
Return connectionString
End Function
Public Shared Function CleanInput(strIn As String) As String
' Replace invalid characters with empty strings.
Try
Return Regex.Replace(strIn, "[^\w\.@-]", "")
' If we timeout when replacing invalid characters,
' we should return String.Empty.
Catch e As RegexMatchTimeoutException
Return String.Empty
End Try
End Function
End Class

View File

@ -9,14 +9,6 @@ Public Class ClassParamRefresh
Catch ex As Exception
WORKING_MODE = ""
End Try
'Try
' ADDITIONAL_TITLE = DT_CHECKUSER.Rows(0).Item("ADDITIONAL_TITLE")
' If ADDITIONAL_TITLE = String.Empty Then
' ADDITIONAL_TITLE = My.Application.Info.ProductName
' End If
'Catch ex As Exception
' ADDITIONAL_TITLE = My.Application.Info.ProductName
'End Try
Dim oSplitWorkMode As String() = WORKING_MODE.Split("#")
@ -26,15 +18,12 @@ Public Class ClassParamRefresh
LOGGER.Debug($"oWorkingMode Parameter: {oMode}")
If oMode.StartsWith("IDB_CONID!") Then
Dim oConnectionId = oMode.Replace("GLOBIX.IDB_CONID!", "")
'Dim oConString = ClassDatabase.Get_ConnectionString(oConnectionId)
Dim oConString = DATABASE_ECM.Get_ConnectionStringforID(oConnectionId)
CONNECTION_STRING_IDB = oConString
DATABASE_IDB = New MSSQLServer(LOGCONFIG, CONNECTION_STRING_IDB)
Dim oSQL = $"SELECT * FROM TBIDB_ATTRIBUTE"
' Dim oDT As DataTable = ClassDatabase.Return_Datatable_CS(oSQL, CONNECTION_STRING_IDB)
Dim oDT As DataTable = DATABASE_IDB.GetDatatable(oSQL)
If Not IsNothing(oDT) Then
@ -48,10 +37,6 @@ Public Class ClassParamRefresh
End If
ElseIf oMode.StartsWith("IDB.LOG_INDEX") Then
IDB_LOG_INDEX = oMode.Replace("IDB.LOG_INDEX!", "")
'ElseIf oMode.StartsWith("PM.COLORSCHEME") Then
' Dim oColorScheme = oMode.Replace("PM.COLORSCHEME=", "")
' RIBBON_COLOR_SCHEME = oColorScheme.ToUpper
Else
LOGGER.Info($"Wrong oMode: {oMode}")
End If

View File

@ -264,7 +264,6 @@
<Compile Include="ClassEncryption.vb" />
<Compile Include="ClassFilehandle.vb" />
<Compile Include="ClassFolderWatcher.vb" />
<Compile Include="ClassFormFunctions.vb" />
<Compile Include="ClassHelper.vb" />
<Compile Include="ClassIDBData.vb" />
<Compile Include="ClassIndexFunctions.vb" />

View File

@ -142,7 +142,7 @@ Public Class frmIndex
If DR.Item("SQL_CHECK").ToString <> String.Empty Then
Dim connectionString As String
Dim sql As String
connectionString = ClassFormFunctions.GetConnectionString(DR.Item("CONNECTION_ID"))
connectionString = DATABASE_ECM.Get_ConnectionStringforID(DR.Item("CONNECTION_ID"))
If connectionString <> "" Then
Dim sqlscalar = DR.Item("SQL_CHECK")
Select Case DR.Item("DATENTYP")
@ -283,7 +283,7 @@ Public Class frmIndex
Function GetAutomaticIndexSQLValue(SQLCommand As String, vconnectionID As Integer, vProvider As String) As String
Try
Dim oConnectionString As String
oConnectionString = ClassFormFunctions.GetConnectionString(vconnectionID)
oConnectionString = DATABASE_ECM.Get_ConnectionStringforID(vconnectionID)
If oConnectionString <> "" Then
'NEU
Dim oErgebnis
@ -1992,7 +1992,7 @@ Public Class frmIndex
Exit Sub
End If
Dim oConnectionString = ClassFormFunctions.GetConnectionString(SqlConnectionId)
Dim oConnectionString = DATABASE_ECM.Get_ConnectionStringforID(SqlConnectionId)
'Dim oDatatable As DataTable = ClassDatabase.Return_Datatable_CS(SqlCommand, oConnectionString)
Dim oDatatable As DataTable = DATABASE_ECM.GetDatatable(SqlCommand)
Dim oFoundControl As Control = Nothing
@ -2725,7 +2725,7 @@ Public Class frmIndex
ClearNotice()
Me.Cursor = Cursors.WaitCursor
ClassHelper.Refresh_RegexTable()
CURRENT_DT_REGEX = DATABASE_ECM.GetDatatable("SELECT * FROM TBGI_FUNCTION_REGEX")
For Each rowregex As DataRow In CURRENT_DT_REGEX.Rows
If rowregex.Item("FUNCTION_NAME") = "CLEAN_FILENAME" Then
REGEX_CLEAN_FILENAME = rowregex.Item("REGEX")

View File

@ -30,7 +30,7 @@ Public Class SQLConfigAutoIndex
Dim dt As DataTable
If typeCS.Length > 0 Then
Dim CS As String
CS = ClassFormFunctions.GetConnectionString(cmbConnection.SelectedValue)
CS = DATABASE_ECM.Get_ConnectionStringforID(cmbConnection.SelectedValue)
If typeCS.ToUpper = "Oracle".ToUpper Then
dt = ClassDatabase.Oracle_Return_Datatable(query, CS, True)
Else
@ -326,7 +326,7 @@ Public Class SQLConfigAutoIndex
If typeCS.Length > 0 Then
Dim oSQL As String = "SELECT TABLE_NAME from information_schema.tables where TABLE_TYPE = " & type & " ORDER BY TABLE_NAME"
Dim CS As String
CS = ClassFormFunctions.GetConnectionString(cmbConnection.SelectedValue)
CS = DATABASE_ECM.Get_ConnectionStringforID(cmbConnection.SelectedValue)
If typeCS.ToUpper = "Oracle".ToUpper Then
@ -362,7 +362,7 @@ Public Class SQLConfigAutoIndex
Private Sub GetColumns(tableName As String, ByRef combobox As ComboBox)
Try
Dim CS As String
CS = ClassFormFunctions.GetConnectionString(cmbConnection.SelectedValue)
CS = DATABASE_ECM.Get_ConnectionStringforID(cmbConnection.SelectedValue)
Dim typeCS As String = DATABASE_ECM.GetScalarValue("SELECT SQL_PROVIDER FROM TBDD_CONNECTION WHERE GUID = " & cmbConnection.SelectedValue)
Dim SQL As String
Dim DT As DataTable

View File

@ -10,7 +10,7 @@ Public Class frmSQLSuggestion
Dim i As Integer
connectionString = ClassFormFunctions.GetConnectionString(conid)
connectionString = DATABASE_ECM.Get_ConnectionStringforID(conid)
If connectionString <> "" Then
If connectionString.Contains("Initial Catalog=") Then
'Dim DT As DataTable = DATABASE_ECM.GetDatatable(sql_Vorschlag)

View File

@ -467,7 +467,7 @@ Public Class frmStart
End If
Opacity = 0.7
ClassHelper.Refresh_RegexTable()
CURRENT_DT_REGEX = DATABASE_ECM.GetDatatable("SELECT * FROM TBGI_FUNCTION_REGEX")
Start_Folderwatch()
ClassWindowLocation.LoadFormLocationSize(Me, LoadSize:=False)