Imports Oracle.ManagedDataAccess.Client Public Class frmConnections Private Sub TBDD_CONNECTIONBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TBDD_CONNECTIONBindingNavigatorSaveItem.Click Try Me.Validate() Me.TBDD_CONNECTIONBindingSource.EndEdit() If Me.MyDataset.TBDD_CONNECTION.GetChanges Is Nothing = False Then Me.GEANDERTWERTextBox.Text = Environment.UserName Me.TBDD_CONNECTIONBindingSource.EndEdit() TBDD_CONNECTIONTableAdapter.Update(MyDataset.TBDD_CONNECTION) Me.lblSave.Visible = True Else Me.lblSave.Visible = False End If Catch ex As Exception MsgBox("Error in Save Connection:" & vbNewLine & ex.Message, MsgBoxStyle.Critical) End Try End Sub Private Sub frmConnections_Load(sender As Object, e As EventArgs) Handles MyBase.Load 'TODO: Diese Codezeile lädt Daten in die Tabelle "MyDataset.TBDD_CONNECTION". Sie können sie bei Bedarf verschieben oder entfernen. Me.TBDD_CONNECTIONTableAdapter.Connection.ConnectionString = MyConnectionString End Sub Sub Load_Conns() Try Me.TBDD_CONNECTIONTableAdapter.Fill(Me.MyDataset.TBDD_CONNECTION) Catch ex As Exception MsgBox("Error in Laod Form: " & vbNewLine & ex.Message, MsgBoxStyle.Critical) End Try End Sub Private Sub SQL_PROVIDERComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles SQL_PROVIDERComboBox.SelectedIndexChanged If Me.SQL_PROVIDERComboBox.SelectedIndex <> -1 Then Me.btnCheck_Con.Visible = True CheckBoxwin_aut.Visible = False chkOR_ohne_TNS.Visible = False Select Case Me.SQL_PROVIDERComboBox.SelectedItem Case "MS-SQL" If USER_LANGUAGE = "de-DE" Then Me.lblDataSource.Text = "Datenbank-Server (IP-Adresse oder Name)*:" Me.lblInitialCatalog.Text = "Datenbank-Name:" Me.lblUserId.Text = "UserId:" Me.lblPassword.Text = "Passwort:" Else Me.lblDataSource.Text = "Database-Server (IP-Adress or Name)*:" Me.lblInitialCatalog.Text = "Database-Name:" Me.lblUserId.Text = "UserId:" Me.lblPassword.Text = "Passwort:" End If Me.SERVERTextBox.ReadOnly = False Me.SERVERTextBox.BackColor = System.Drawing.SystemColors.Window Me.SERVERTextBox.Text = "" Me.lblInitialCatalog.Visible = False Me.DATENBANKTextBox.Visible = False Me.cmbInitialCatalog.Visible = True Me.lblDatenbank.Visible = True CheckBoxwin_aut.Visible = True Case "Oracle" If USER_LANGUAGE = "de-DE" Then Me.lblDataSource.Text = "IP Oracle-Server:" Me.lblInitialCatalog.Text = "Servicename:" Me.lblUserId.Text = "UserId:" Me.lblPassword.Text = "Passwort:" Else Me.lblDataSource.Text = "IP Oracle-Server:" Me.lblInitialCatalog.Text = "Servicename:" Me.lblUserId.Text = "UserId:" Me.lblPassword.Text = "Password:" End If Me.cmbInitialCatalog.Visible = False Me.SERVERTextBox.ReadOnly = False Me.SERVERTextBox.BackColor = System.Drawing.SystemColors.Window Me.SERVERTextBox.Text = "" Me.lblInitialCatalog.Visible = True Me.DATENBANKTextBox.Visible = True chkOR_ohne_TNS.Visible = True End Select Me.lblDataSource.Visible = True Me.lblUserId.Visible = True Me.lblPassword.Visible = True Me.SERVERTextBox.Visible = True Me.USERNAMETextBox.Visible = True Me.PASSWORDTextBox.Visible = True Else Me.lblDataSource.Visible = False Me.lblUserId.Visible = False Me.lblPassword.Visible = False Me.SERVERTextBox.Visible = False Me.USERNAMETextBox.Visible = False Me.PASSWORDTextBox.Visible = False End If End Sub Private Sub CheckBoxwin_aut_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBoxwin_aut.CheckedChanged If CheckBoxwin_aut.Checked Then Me.USERNAMETextBox.Enabled = False Me.PASSWORDTextBox.Enabled = False Me.USERNAMETextBox.Text = "WINAUTH" Me.PASSWORDTextBox.Text = "" Else Me.USERNAMETextBox.Enabled = True Me.PASSWORDTextBox.Enabled = True Me.USERNAMETextBox.Text = "" Me.PASSWORDTextBox.Text = "" End If End Sub Private Sub chkOR_ohne_TNS_CheckedChanged(sender As Object, e As EventArgs) Handles chkOR_ohne_TNS.CheckedChanged If chkOR_ohne_TNS.Checked Then Me.BEMERKUNGTextBox.Text = "without tnsnames" Else Me.BEMERKUNGTextBox.Text = "" End If End Sub Private Sub btnCheck_Con_Click(sender As Object, e As EventArgs) Handles btnCheck_Con.Click Dim msg_string As String Try If Me.SQL_PROVIDERComboBox.SelectedIndex <> -1 Then Cursor = Cursors.WaitCursor Select Case Me.SQL_PROVIDERComboBox.SelectedItem Case "MS-SQL" Dim con As String If CheckBoxwin_aut.Checked Then con = "Data Source=" & Me.SERVERTextBox.Text & ";Initial Catalog=" & Me.cmbInitialCatalog.Text & ";Trusted_Connection=True;" Else con = "Server=" & Me.SERVERTextBox.Text & ";Database=" & Me.cmbInitialCatalog.Text & ";User Id=" & Me.USERNAMETextBox.Text & ";Password=" & Me.PASSWORDTextBox.Text & ";" End If msg_string = con Dim connection As New SqlClient.SqlConnection(con) connection.Open() Cursor = Cursors.Default If USER_LANGUAGE = "de-DE" Then MsgBox("Die SQL-Server Verbindung wurde erfolgreich aufgebaut!", MsgBoxStyle.Information, "Erfolg:") Else MsgBox("Connection to Server successfully established!", MsgBoxStyle.Information, "Success:") End If My.Settings.Save() 'DialogResult = Windows.Forms.DialogResult.OK Case "Oracle" My.Settings.Save() Dim connstr As String Try 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 Dim connection As New OracleConnection(connstr) connection.Open() If USER_LANGUAGE = "de-DE" Then MsgBox("Die SQL-Server Verbindung wurde erfolgreich aufgebaut!", MsgBoxStyle.Information, "Erfolg:") Else MsgBox("Connection to Server successfully established!", MsgBoxStyle.Information, "Success:") End If My.Settings.Save() Catch ex As Exception MsgBox(ex.Message & vbNewLine & vbNewLine & connstr, MsgBoxStyle.Critical, "Unexpected error in Verbindungsaufbau Oracle:") End Try Case Else If USER_LANGUAGE = "de-DE" Then MsgBox("Test zur Zeit nicht möglich", MsgBoxStyle.Information, "Achtung:") Else MsgBox("Test not available", MsgBoxStyle.Information, "Warning:") End If End Select End If Catch ex As Exception Dim template As String = ex.Message Clipboard.SetDataObject(template) MsgBox("Unexpected error inm Verbindungsaufbau: " & vbNewLine & ex.Message & vbNewLine & "Connection-String: " & vbNewLine & msg_string, MsgBoxStyle.Critical) End Try Cursor = Cursors.Default End Sub Private Sub cmbInitialCatalog_Click(sender As Object, e As EventArgs) Handles cmbInitialCatalog.Click Get_MSSQL_Databases() End Sub Sub Get_MSSQL_Databases() Try ' Dim csb As New SqlClient.SqlConnectionStringBuilder If Me.SQL_PROVIDERComboBox.SelectedIndex <> -1 Then Select Case Me.SQL_PROVIDERComboBox.SelectedItem Case "MS-SQL" Dim con As String If CheckBoxwin_aut.Checked Then con = "Data Source=" & Me.SERVERTextBox.Text & ";Initial Catalog=" & Me.cmbInitialCatalog.Text & ";Trusted_Connection=True;" Else con = "Server=" & Me.SERVERTextBox.Text & ";Database=" & Me.cmbInitialCatalog.Text & ";User Id=" & Me.USERNAMETextBox.Text & ";Password=" & Me.PASSWORDTextBox.Text & ";" End If 'csb.DataSource = Me.txtDataSource.Text 'csb.IntegratedSecurity = False 'csb.UserID = Me.txtUserId.Text 'csb.Password = Me.txtPassword.Text Dim connection As New SqlClient.SqlConnection(con) 'während Verbindungsaufbau Sanduhr-Mauszeiger Cursor = Cursors.WaitCursor connection.Open() Cursor = Cursors.Default ' SQLCommand-Objekt über alle Datenbanken erstellen Dim cmd As New SqlClient.SqlCommand("SELECT [name] FROM master.dbo.sysdatabases WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')", connection) 'cmd.CommandType = CommandType. ' Ausführen und Ergebnis in einer ListBox anzeigen Dim dr As SqlClient.SqlDataReader = cmd.ExecuteReader If dr.HasRows Then cmbInitialCatalog.Items.Clear() Do While dr.Read cmbInitialCatalog.Items.Add(dr("name")) Loop cmbInitialCatalog.DroppedDown = True End If End Select End If Catch ex As Exception Cursor = Cursors.Default Dim template As String = ex.Message Clipboard.SetDataObject(template) MsgBox("Unexpected error inm Verbindungsaufbau: " & vbNewLine & ex.Message, MsgBoxStyle.Exclamation) End Try End Sub Private Sub TBDD_CONNECTIONBindingSource_AddingNew(sender As Object, e As System.ComponentModel.AddingNewEventArgs) Handles TBDD_CONNECTIONBindingSource.AddingNew Me.MyDataset.TBDD_CONNECTION.ERSTELLTWERColumn.DefaultValue = Environment.UserName End Sub Private Sub ToolStripButton1_Click(sender As Object, e As EventArgs) Handles ToolStripButton1.Click Load_Conns() End Sub Private Sub TBDD_CONNECTIONBindingSource_CurrentChanged(sender As Object, e As EventArgs) Handles TBDD_CONNECTIONBindingSource.CurrentChanged Me.lblSave.Visible = False End Sub Private Sub BEMERKUNGTextBox_TextChanged(sender As Object, e As EventArgs) Handles BEMERKUNGTextBox.TextChanged If BEMERKUNGTextBox.Text.Contains("without tnsnames") Then Me.chkOR_ohne_TNS.Checked = True Else Me.chkOR_ohne_TNS.Checked = False End If End Sub Private Sub frmConnections_Shown(sender As Object, e As EventArgs) Handles Me.Shown Load_Conns() Threading.Thread.Sleep(300) Load_Conns() End Sub End Class