This commit is contained in:
Jonathan Jenne
2019-08-02 16:27:35 +02:00
parent 28d5e590b4
commit 926801f7ba
29 changed files with 6191 additions and 2821 deletions

View File

@@ -0,0 +1,178 @@
Imports System.Data.SqlClient
Imports Oracle.ManagedDataAccess.Client
Public Class frmConnection
Private Const PROVIDER_ORACLE = "ORACLE"
Private Const PROVIDER_MSSQL = "MS-SQL"
Private Sub TBDD_CONNECTIONBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs)
Validate()
TBDD_CONNECTIONBindingSource.EndEdit()
TableAdapterManager.UpdateAll(MyDataset)
End Sub
Private Sub frmConnection_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Load_Connections()
End Sub
Private Sub Load_Connections()
Try
TBDD_CONNECTIONTableAdapter.Connection.ConnectionString = MyConnectionString
TBDD_CONNECTIONTableAdapter.Fill(MyDataset.TBDD_CONNECTION)
Catch ex As Exception
Logger.Error(ex)
MsgBox("Fehler beim Laden der Verbindungen: " & vbNewLine & ex.Message, MsgBoxStyle.Critical, Text)
End Try
End Sub
Private Sub TBDD_CONNECTIONBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBDD_CONNECTIONBindingSource.AddingNew
MyDataset.TBDD_CONNECTION.AKTIVColumn.DefaultValue = True
MyDataset.TBDD_CONNECTION.ERSTELLTWERColumn.DefaultValue = Environment.UserName
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ConnectionTest(SQL_PROVIDERComboBox.Text, chkWinAuth.Checked, SERVERTextBox.Text, USERNAMETextBox.Text, PASSWORDTextBox.Text, DATENBANKComboBox.Text)
End Sub
Private Sub ConnectionTest(ConnectionType As String, WinAuth As Boolean, Server As String, UserId As String, Password As String, Database As String)
Dim oConnectionString As String = String.Empty
Select Case ConnectionType
Case PROVIDER_MSSQL
If WinAuth Then
oConnectionString = $"Data Source={Server};Initial Catalog={Database};Trusted_Connection=True;"
Else
oConnectionString = $"Server={Server};Database={Database};User Id={UserId};Password={Password};"
End If
Cursor = Cursors.WaitCursor
Using oConnection As New SqlConnection(oConnectionString)
Try
oConnection.Open()
MsgBox("Die Verbindung wurde erfolgreich aufgebaut!", MsgBoxStyle.Information, Text)
Catch ex As Exception
Logger.Error(ex)
MsgBox("Fehler beim Verbindungsaufbau: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation, Text)
Finally
Cursor = Cursors.Default
End Try
End Using
Case PROVIDER_ORACLE
Try
Dim conn As New OracleConnectionStringBuilder
oConnectionString = $"Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST={Server})(PORT=1521)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME={Database})));User Id={UserId};Password={Password};"
'conn.DataSource = DATENBANKComboBox.Text
'conn.UserID = txtUserId.Text
'conn.Password = txtPassword.Text
'conn.PersistSecurityInfo = True
'conn.ConnectionTimeout = 120
'oConnectionString = conn.ConnectionString
Using connection As New OracleConnection(oConnectionString)
connection.Open()
End Using
MsgBox("Die Verbindung wurde erfolgreich aufgebaut!", MsgBoxStyle.Information, Text)
Catch ex As Exception
Logger.Error(ex)
MsgBox(ex.Message & vbNewLine & vbNewLine & oConnectionString, MsgBoxStyle.Critical, "Fehler bei Verbindungsaufbau Oracle:")
End Try
End Select
End Sub
Private Sub DATENBANKComboBox_Click(sender As Object, e As EventArgs) Handles DATENBANKComboBox.Click
Cursor = Cursors.WaitCursor
Dim oConnectionBuilder As New SqlConnectionStringBuilder
If SERVERTextBox.Text = String.Empty Then
MsgBox("Bitte geben sie einen Server an!")
Exit Sub
End If
If SQL_PROVIDERComboBox.Text = PROVIDER_ORACLE Then
Exit Sub
End If
If chkWinAuth.Checked Then
oConnectionBuilder.DataSource = SERVERTextBox.Text
oConnectionBuilder.IntegratedSecurity = True
Else
If USERNAMETextBox.Text = String.Empty Or PASSWORDTextBox.Text = String.Empty Then
MsgBox("Bitte geben sie Benutzer und Passwort an!", MsgBoxStyle.Exclamation, Text)
Exit Sub
End If
oConnectionBuilder.DataSource = SERVERTextBox.Text
oConnectionBuilder.IntegratedSecurity = False
oConnectionBuilder.UserID = USERNAMETextBox.Text
oConnectionBuilder.Password = PASSWORDTextBox.Text
End If
Try
Using oConnection As New SqlConnection(oConnectionBuilder.ToString)
oConnection.Open()
Using oCmd As New SqlCommand("sp_databases", oConnection) With {.CommandType = CommandType.StoredProcedure}
Using oReader As SqlDataReader = oCmd.ExecuteReader
If oReader.HasRows Then
DATENBANKComboBox.Items.Clear()
Do While oReader.Read()
DATENBANKComboBox.Items.Add(oReader.Item("Database_Name"))
Loop
DATENBANKComboBox.DroppedDown = True
Else
MsgBox("The standard-databases could not be retrieved." & vbNewLine & "Check rights in sql-server for user", MsgBoxStyle.Exclamation)
End If
End Using
End Using
End Using
Catch ex As Exception
Logger.Error(ex)
MsgBox("Error while loading Databases:" & vbCrLf & ex.Message, MsgBoxStyle.Critical, Text)
Finally
Cursor = Cursors.Default
End Try
End Sub
Private Sub chkWinAuth_CheckedChanged(sender As Object, e As EventArgs) Handles chkWinAuth.CheckedChanged
If chkWinAuth.Checked Then
USERNAMETextBox.Enabled = False
USERNAMETextBox.Text = "WINAUTH"
PASSWORDTextBox.Enabled = False
PASSWORDTextBox.Text = ""
Else
USERNAMETextBox.Enabled = True
USERNAMETextBox.Text = ""
PASSWORDTextBox.Enabled = True
PASSWORDTextBox.Text = ""
End If
End Sub
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonAdd.ItemClick
TBDD_CONNECTIONBindingSource.AddNew()
End Sub
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonDelete.ItemClick
Try
If GUIDTextBox.Text <> String.Empty Then
Dim oResult As MsgBoxResult = MsgBox("Wollen Sie die Verbindung wirklich löschen?", MsgBoxStyle.YesNo, Text)
If oResult = MsgBoxResult.Yes Then
TBDD_CONNECTIONTableAdapter.Delete(GUIDTextBox.Text)
End If
End If
Catch ex As Exception
Logger.Error(ex)
MsgBox("Fehler beim Löschen der Verbindung: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Private Sub BarButtonItem3_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonSave.ItemClick
Validate()
TBDD_CONNECTIONBindingSource.EndEdit()
TableAdapterManager.UpdateAll(MyDataset)
End Sub
End Class