diff --git a/DDMonorepo.sln b/DDMonorepo.sln index e03232eb..e98fd03a 100644 --- a/DDMonorepo.sln +++ b/DDMonorepo.sln @@ -68,8 +68,6 @@ Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "SnapPanel", "Controls.SnapP EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "GlobalIndexer", "GUIs.GlobalIndexer\GlobalIndexer.vbproj", "{40384B94-1F94-4249-9A5A-D02E0B346738}" EndProject -Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "SQLConfig", "SQLConfig\SQLConfig.vbproj", "{65EFB268-C0E0-40C1-8981-9F70DEE5C74A}" -EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "MonoRepoUtils", "ConfigCreator\MonoRepoUtils.vbproj", "{9D4AC920-C78E-41C3-994E-91690FF79380}" EndProject Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "DBCleaner", "DBCleaner\DBCleaner.vbproj", "{5A7913CE-7D3D-4E84-B23D-4747C178CD71}" @@ -170,10 +168,6 @@ Global {40384B94-1F94-4249-9A5A-D02E0B346738}.Debug|Any CPU.Build.0 = Debug|Any CPU {40384B94-1F94-4249-9A5A-D02E0B346738}.Release|Any CPU.ActiveCfg = Release|Any CPU {40384B94-1F94-4249-9A5A-D02E0B346738}.Release|Any CPU.Build.0 = Release|Any CPU - {65EFB268-C0E0-40C1-8981-9F70DEE5C74A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {65EFB268-C0E0-40C1-8981-9F70DEE5C74A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {65EFB268-C0E0-40C1-8981-9F70DEE5C74A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {65EFB268-C0E0-40C1-8981-9F70DEE5C74A}.Release|Any CPU.Build.0 = Release|Any CPU {9D4AC920-C78E-41C3-994E-91690FF79380}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9D4AC920-C78E-41C3-994E-91690FF79380}.Debug|Any CPU.Build.0 = Debug|Any CPU {9D4AC920-C78E-41C3-994E-91690FF79380}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -213,7 +207,6 @@ Global {F0A807CC-BE14-4B5B-9200-27C16156BD8A} = {F98C0329-C004-417F-B2AB-7466E88D8220} {3E19C413-3197-4635-944E-558FC04C3475} = {F98C0329-C004-417F-B2AB-7466E88D8220} {40384B94-1F94-4249-9A5A-D02E0B346738} = {8FFE925E-8B84-45F1-93CB-32B1C96F41EB} - {65EFB268-C0E0-40C1-8981-9F70DEE5C74A} = {F98C0329-C004-417F-B2AB-7466E88D8220} {9D4AC920-C78E-41C3-994E-91690FF79380} = {8FFE925E-8B84-45F1-93CB-32B1C96F41EB} {5A7913CE-7D3D-4E84-B23D-4747C178CD71} = {CC368D6A-6AC4-4EB9-A092-14700FABEF7A} {E3DA65CA-964D-4896-991A-B5426884E215} = {7AF3F9C2-C939-4A08-95C1-0453207E298A} diff --git a/GUIs.Common/Common.vbproj b/GUIs.Common/Common.vbproj index 9332b3c5..3faffb7d 100644 --- a/GUIs.Common/Common.vbproj +++ b/GUIs.Common/Common.vbproj @@ -198,6 +198,12 @@ Form + + frmSQLConfig.vb + + + Form + frmSQLEditor.vb @@ -277,6 +283,9 @@ frmNotification_Startup.vb + + frmSQLConfig.vb + frmSQLEditor.vb diff --git a/GUIs.Common/frmSQLConfig.Designer.vb b/GUIs.Common/frmSQLConfig.Designer.vb new file mode 100644 index 00000000..03402a96 --- /dev/null +++ b/GUIs.Common/frmSQLConfig.Designer.vb @@ -0,0 +1,271 @@ + _ +Partial Class frmSQLConfig + Inherits DevExpress.XtraEditors.XtraForm + + 'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen. + _ + Protected Overrides Sub Dispose(ByVal disposing As Boolean) + Try + If disposing AndAlso components IsNot Nothing Then + components.Dispose() + End If + Finally + MyBase.Dispose(disposing) + End Try + End Sub + + 'Wird vom Windows Form-Designer benötigt. + Private components As System.ComponentModel.IContainer + + 'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich. + 'Das Bearbeiten ist mit dem Windows Form-Designer möglich. + 'Das Bearbeiten mit dem Code-Editor ist nicht möglich. + _ + Private Sub InitializeComponent() + Me.LayoutControl1 = New DevExpress.XtraLayout.LayoutControl() + Me.txtServerName = New DevExpress.XtraEditors.TextEdit() + Me.txtUserName = New DevExpress.XtraEditors.TextEdit() + Me.txtPassword = New DevExpress.XtraEditors.TextEdit() + Me.cmbDatabase = New DevExpress.XtraEditors.ComboBoxEdit() + Me.btnTestConnection = New DevExpress.XtraEditors.SimpleButton() + Me.txtConnectionString = New DevExpress.XtraEditors.TextEdit() + Me.chkWinAuth = New DevExpress.XtraEditors.CheckEdit() + Me.LayoutControlGroup1 = New DevExpress.XtraLayout.LayoutControlGroup() + Me.LayoutControlItem1 = New DevExpress.XtraLayout.LayoutControlItem() + Me.LayoutControlItem2 = New DevExpress.XtraLayout.LayoutControlItem() + Me.LayoutControlItem4 = New DevExpress.XtraLayout.LayoutControlItem() + Me.LayoutControlItem3 = New DevExpress.XtraLayout.LayoutControlItem() + Me.LayoutControlItem7 = New DevExpress.XtraLayout.LayoutControlItem() + Me.LayoutControlItem6 = New DevExpress.XtraLayout.LayoutControlItem() + Me.LayoutControlItem5 = New DevExpress.XtraLayout.LayoutControlItem() + Me.EmptySpaceItem2 = New DevExpress.XtraLayout.EmptySpaceItem() + CType(Me.LayoutControl1, System.ComponentModel.ISupportInitialize).BeginInit() + Me.LayoutControl1.SuspendLayout() + CType(Me.txtServerName.Properties, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.txtUserName.Properties, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.txtPassword.Properties, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.cmbDatabase.Properties, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.txtConnectionString.Properties, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.chkWinAuth.Properties, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.LayoutControlGroup1, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.LayoutControlItem1, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.LayoutControlItem2, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.LayoutControlItem4, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.LayoutControlItem3, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.LayoutControlItem7, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.LayoutControlItem6, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.LayoutControlItem5, System.ComponentModel.ISupportInitialize).BeginInit() + CType(Me.EmptySpaceItem2, System.ComponentModel.ISupportInitialize).BeginInit() + Me.SuspendLayout() + ' + 'LayoutControl1 + ' + Me.LayoutControl1.Controls.Add(Me.txtServerName) + Me.LayoutControl1.Controls.Add(Me.txtUserName) + Me.LayoutControl1.Controls.Add(Me.txtPassword) + Me.LayoutControl1.Controls.Add(Me.cmbDatabase) + Me.LayoutControl1.Controls.Add(Me.btnTestConnection) + Me.LayoutControl1.Controls.Add(Me.txtConnectionString) + Me.LayoutControl1.Controls.Add(Me.chkWinAuth) + Me.LayoutControl1.Dock = System.Windows.Forms.DockStyle.Fill + Me.LayoutControl1.Location = New System.Drawing.Point(0, 0) + Me.LayoutControl1.Name = "LayoutControl1" + Me.LayoutControl1.Root = Me.LayoutControlGroup1 + Me.LayoutControl1.Size = New System.Drawing.Size(602, 221) + Me.LayoutControl1.TabIndex = 0 + Me.LayoutControl1.Text = "LayoutControl1" + ' + 'txtServerName + ' + Me.txtServerName.Location = New System.Drawing.Point(160, 15) + Me.txtServerName.Name = "txtServerName" + Me.txtServerName.Size = New System.Drawing.Size(427, 20) + Me.txtServerName.StyleController = Me.LayoutControl1 + Me.txtServerName.TabIndex = 4 + ' + 'txtUserName + ' + Me.txtUserName.Location = New System.Drawing.Point(160, 45) + Me.txtUserName.Name = "txtUserName" + Me.txtUserName.Size = New System.Drawing.Size(136, 20) + Me.txtUserName.StyleController = Me.LayoutControl1 + Me.txtUserName.TabIndex = 5 + ' + 'txtPassword + ' + Me.txtPassword.Location = New System.Drawing.Point(451, 45) + Me.txtPassword.Name = "txtPassword" + Me.txtPassword.Size = New System.Drawing.Size(136, 20) + Me.txtPassword.StyleController = Me.LayoutControl1 + Me.txtPassword.TabIndex = 6 + ' + 'cmbDatabase + ' + Me.cmbDatabase.Location = New System.Drawing.Point(160, 75) + Me.cmbDatabase.Name = "cmbDatabase" + Me.cmbDatabase.Properties.Buttons.AddRange(New DevExpress.XtraEditors.Controls.EditorButton() {New DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)}) + Me.cmbDatabase.Size = New System.Drawing.Size(427, 20) + Me.cmbDatabase.StyleController = Me.LayoutControl1 + Me.cmbDatabase.TabIndex = 7 + ' + 'btnTestConnection + ' + Me.btnTestConnection.ImageOptions.SvgImageSize = New System.Drawing.Size(16, 16) + Me.btnTestConnection.Location = New System.Drawing.Point(303, 164) + Me.btnTestConnection.Name = "btnTestConnection" + Me.btnTestConnection.Size = New System.Drawing.Size(287, 22) + Me.btnTestConnection.StyleController = Me.LayoutControl1 + Me.btnTestConnection.TabIndex = 8 + Me.btnTestConnection.Text = "Verbindung zur Datenbank herstellen" + ' + 'txtConnectionString + ' + Me.txtConnectionString.Location = New System.Drawing.Point(160, 137) + Me.txtConnectionString.Name = "txtConnectionString" + Me.txtConnectionString.Properties.ReadOnly = True + Me.txtConnectionString.Size = New System.Drawing.Size(427, 20) + Me.txtConnectionString.StyleController = Me.LayoutControl1 + Me.txtConnectionString.TabIndex = 9 + ' + 'chkWinAuth + ' + Me.chkWinAuth.Location = New System.Drawing.Point(17, 107) + Me.chkWinAuth.Name = "chkWinAuth" + Me.chkWinAuth.Properties.Caption = "Windows Authentifizierung" + Me.chkWinAuth.Size = New System.Drawing.Size(568, 18) + Me.chkWinAuth.StyleController = Me.LayoutControl1 + Me.chkWinAuth.TabIndex = 10 + ' + 'LayoutControlGroup1 + ' + Me.LayoutControlGroup1.EnableIndentsWithoutBorders = DevExpress.Utils.DefaultBoolean.[True] + Me.LayoutControlGroup1.GroupBordersVisible = False + Me.LayoutControlGroup1.Items.AddRange(New DevExpress.XtraLayout.BaseLayoutItem() {Me.LayoutControlItem1, Me.LayoutControlItem2, Me.LayoutControlItem4, Me.LayoutControlItem3, Me.LayoutControlItem7, Me.LayoutControlItem6, Me.LayoutControlItem5, Me.EmptySpaceItem2}) + Me.LayoutControlGroup1.Name = "LayoutControlGroup1" + Me.LayoutControlGroup1.Size = New System.Drawing.Size(602, 221) + Me.LayoutControlGroup1.TextVisible = False + ' + 'LayoutControlItem1 + ' + Me.LayoutControlItem1.Control = Me.txtServerName + Me.LayoutControlItem1.Location = New System.Drawing.Point(0, 0) + Me.LayoutControlItem1.Name = "LayoutControlItem1" + Me.LayoutControlItem1.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) + Me.LayoutControlItem1.Size = New System.Drawing.Size(582, 30) + Me.LayoutControlItem1.Text = "Server Name:" + Me.LayoutControlItem1.TextSize = New System.Drawing.Size(142, 13) + ' + 'LayoutControlItem2 + ' + Me.LayoutControlItem2.Control = Me.txtUserName + Me.LayoutControlItem2.Location = New System.Drawing.Point(0, 30) + Me.LayoutControlItem2.Name = "LayoutControlItem2" + Me.LayoutControlItem2.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) + Me.LayoutControlItem2.Size = New System.Drawing.Size(291, 30) + Me.LayoutControlItem2.Text = "Benutzername:" + Me.LayoutControlItem2.TextSize = New System.Drawing.Size(142, 13) + ' + 'LayoutControlItem4 + ' + Me.LayoutControlItem4.Control = Me.cmbDatabase + Me.LayoutControlItem4.Location = New System.Drawing.Point(0, 60) + Me.LayoutControlItem4.Name = "LayoutControlItem4" + Me.LayoutControlItem4.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) + Me.LayoutControlItem4.Size = New System.Drawing.Size(582, 30) + Me.LayoutControlItem4.Text = "Datenbank:" + Me.LayoutControlItem4.TextSize = New System.Drawing.Size(142, 13) + ' + 'LayoutControlItem3 + ' + Me.LayoutControlItem3.Control = Me.txtPassword + Me.LayoutControlItem3.Location = New System.Drawing.Point(291, 30) + Me.LayoutControlItem3.Name = "LayoutControlItem3" + Me.LayoutControlItem3.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) + Me.LayoutControlItem3.Size = New System.Drawing.Size(291, 30) + Me.LayoutControlItem3.Text = "Passwort:" + Me.LayoutControlItem3.TextSize = New System.Drawing.Size(142, 13) + ' + 'LayoutControlItem7 + ' + Me.LayoutControlItem7.Control = Me.chkWinAuth + Me.LayoutControlItem7.Location = New System.Drawing.Point(0, 90) + Me.LayoutControlItem7.Name = "LayoutControlItem7" + Me.LayoutControlItem7.Size = New System.Drawing.Size(582, 32) + Me.LayoutControlItem7.Spacing = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) + Me.LayoutControlItem7.TextSize = New System.Drawing.Size(0, 0) + Me.LayoutControlItem7.TextVisible = False + ' + 'LayoutControlItem6 + ' + Me.LayoutControlItem6.Control = Me.txtConnectionString + Me.LayoutControlItem6.Location = New System.Drawing.Point(0, 122) + Me.LayoutControlItem6.Name = "LayoutControlItem6" + Me.LayoutControlItem6.Padding = New DevExpress.XtraLayout.Utils.Padding(5, 5, 5, 5) + Me.LayoutControlItem6.Size = New System.Drawing.Size(582, 30) + Me.LayoutControlItem6.Text = "Aktueller Connectionstring:" + Me.LayoutControlItem6.TextSize = New System.Drawing.Size(142, 13) + ' + 'LayoutControlItem5 + ' + Me.LayoutControlItem5.Control = Me.btnTestConnection + Me.LayoutControlItem5.Location = New System.Drawing.Point(291, 152) + Me.LayoutControlItem5.Name = "LayoutControlItem5" + Me.LayoutControlItem5.Size = New System.Drawing.Size(291, 49) + Me.LayoutControlItem5.TextSize = New System.Drawing.Size(0, 0) + Me.LayoutControlItem5.TextVisible = False + ' + 'EmptySpaceItem2 + ' + Me.EmptySpaceItem2.AllowHotTrack = False + Me.EmptySpaceItem2.Location = New System.Drawing.Point(0, 152) + Me.EmptySpaceItem2.Name = "EmptySpaceItem2" + Me.EmptySpaceItem2.Size = New System.Drawing.Size(291, 49) + Me.EmptySpaceItem2.TextSize = New System.Drawing.Size(0, 0) + ' + 'frmSQLConfig + ' + Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) + Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font + Me.ClientSize = New System.Drawing.Size(602, 221) + Me.Controls.Add(Me.LayoutControl1) + Me.Name = "frmSQLConfig" + Me.Text = "Datenbank Verbindung" + CType(Me.LayoutControl1, System.ComponentModel.ISupportInitialize).EndInit() + Me.LayoutControl1.ResumeLayout(False) + CType(Me.txtServerName.Properties, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.txtUserName.Properties, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.txtPassword.Properties, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.cmbDatabase.Properties, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.txtConnectionString.Properties, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.chkWinAuth.Properties, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.LayoutControlGroup1, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.LayoutControlItem1, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.LayoutControlItem2, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.LayoutControlItem4, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.LayoutControlItem3, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.LayoutControlItem7, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.LayoutControlItem6, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.LayoutControlItem5, System.ComponentModel.ISupportInitialize).EndInit() + CType(Me.EmptySpaceItem2, System.ComponentModel.ISupportInitialize).EndInit() + Me.ResumeLayout(False) + + End Sub + + Friend WithEvents LayoutControl1 As DevExpress.XtraLayout.LayoutControl + Friend WithEvents LayoutControlGroup1 As DevExpress.XtraLayout.LayoutControlGroup + Friend WithEvents txtServerName As DevExpress.XtraEditors.TextEdit + Friend WithEvents txtUserName As DevExpress.XtraEditors.TextEdit + Friend WithEvents txtPassword As DevExpress.XtraEditors.TextEdit + Friend WithEvents cmbDatabase As DevExpress.XtraEditors.ComboBoxEdit + Friend WithEvents btnTestConnection As DevExpress.XtraEditors.SimpleButton + Friend WithEvents txtConnectionString As DevExpress.XtraEditors.TextEdit + Friend WithEvents chkWinAuth As DevExpress.XtraEditors.CheckEdit + Friend WithEvents LayoutControlItem1 As DevExpress.XtraLayout.LayoutControlItem + Friend WithEvents LayoutControlItem2 As DevExpress.XtraLayout.LayoutControlItem + Friend WithEvents LayoutControlItem4 As DevExpress.XtraLayout.LayoutControlItem + Friend WithEvents LayoutControlItem3 As DevExpress.XtraLayout.LayoutControlItem + Friend WithEvents LayoutControlItem7 As DevExpress.XtraLayout.LayoutControlItem + Friend WithEvents LayoutControlItem6 As DevExpress.XtraLayout.LayoutControlItem + Friend WithEvents LayoutControlItem5 As DevExpress.XtraLayout.LayoutControlItem + Friend WithEvents EmptySpaceItem2 As DevExpress.XtraLayout.EmptySpaceItem +End Class diff --git a/GUIs.Common/frmSQLConfig.resx b/GUIs.Common/frmSQLConfig.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/GUIs.Common/frmSQLConfig.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GUIs.Common/frmSQLConfig.vb b/GUIs.Common/frmSQLConfig.vb new file mode 100644 index 00000000..74149683 --- /dev/null +++ b/GUIs.Common/frmSQLConfig.vb @@ -0,0 +1,154 @@ +Imports System.ComponentModel +Imports System.Data.SqlClient +Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Encryption +Imports DigitalData.Modules.Filesystem +Imports DigitalData.Modules.Logging + +Public Class frmSQLConfig + Private Const STRING_CONNECTION_SUCCESSFUL = "Die Verbindung wurde erfolgreich aufgebaut!" & vbNewLine & "Möchten Sie diese Verbindung nun in der Anwendung speichern?" + + Private ReadOnly Logger As Logger + Private ReadOnly LogConfig As LogConfig + + Public Property ConnectionString As String = String.Empty + Public Property FormTitle As String = "" + + Public Sub New() + ' Dieser Aufruf ist für den Designer erforderlich. + InitializeComponent() + + ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. + End Sub + + Public Sub New(LogConfig As LogConfig) + ' Dieser Aufruf ist für den Designer erforderlich. + InitializeComponent() + + ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. + Me.LogConfig = LogConfig + Logger = LogConfig.GetLogger() + End Sub + + Private Sub frmSQLConfig_Load(sender As Object, e As EventArgs) Handles MyBase.Load + Dim oConnectionString = ConnectionString + + If FormTitle.Count > 0 Then + Text = $"{FormTitle} - {Text}" + End If + + If Not oConnectionString = String.Empty Then + Dim oBuilder As SqlConnectionStringBuilder + Try + oBuilder = New SqlConnectionStringBuilder(ConnectionString) + Catch ex As Exception + oBuilder = Nothing + End Try + + If oBuilder Is Nothing Then + MsgBox("Connection String ist ungültig!", MsgBoxStyle.Critical, Text) + Exit Sub + End If + + If oConnectionString.Contains("Trusted") Then + chkWinAuth.Checked = True + txtConnectionString.Text = oConnectionString + Else + chkWinAuth.Checked = False + txtConnectionString.Text = oConnectionString.Replace(oBuilder.Password, "XXXXXX") + txtUserName.Text = oBuilder.UserID + End If + + txtServerName.Text = oBuilder.DataSource + cmbDatabase.Text = oBuilder.InitialCatalog + End If + End Sub + + Private Sub chkWinAuth_CheckedChanged(sender As Object, e As EventArgs) Handles chkWinAuth.CheckedChanged + txtPassword.Enabled = Not chkWinAuth.Checked + txtUserName.Enabled = Not chkWinAuth.Checked + End Sub + + Private Sub cmbDatabase_Click(sender As Object, e As EventArgs) Handles cmbDatabase.Click + Cursor = Cursors.WaitCursor + + Dim oConnectionString As String = GetConnectionString(False) + Dim oDatabase As New MSSQLServer(LogConfig, oConnectionString) + + If oDatabase.DBInitialized = False Then + MsgBox("Verbindung fehlgeschlagen!", MsgBoxStyle.Critical, Text) + Exit Sub + End If + + Try + Using oConnection = New SqlClient.SqlConnection(oConnectionString) + oConnection.Open() + Using oCommand As New SqlClient.SqlCommand("sp_databases", oConnection) + Using oReader As SqlClient.SqlDataReader = oCommand.ExecuteReader + If oReader.HasRows Then + cmbDatabase.Properties.Items.Clear() + + Do While oReader.Read + cmbDatabase.Properties.Items.Add(oReader("Database_Name")) + Loop + cmbDatabase.ShowPopup() + Else + MsgBox("The standard-databases could not be retrieved. The default database will be set!" & vbNewLine & "Check rights in sql-server for user: " & Me.txtUserName.Text, MsgBoxStyle.Exclamation) + End If + End Using + End Using + End Using + + Catch ex As Exception + Logger.Error(ex) + Finally + Cursor = Cursors.Default + End Try + End Sub + + Private Function GetConnectionString(WithDatabase As Boolean) As String + Dim oConnectionString As String + + If chkWinAuth.Checked Then + oConnectionString = $"Data Source={txtServerName.Text};Trusted_Connection=True;" + Else + oConnectionString = $"Server={txtServerName.Text};User Id={txtUserName.Text};Password={txtPassword.Text};" + End If + + If WithDatabase Then + oConnectionString &= $"Database={cmbDatabase.Text};" + End If + + Return oConnectionString + End Function + + Private Sub btnTestConnection_Click(sender As Object, e As EventArgs) Handles btnTestConnection.Click + Try + Dim oConnectionString = GetConnectionString(True) + + Using oConnection As New SqlConnection(oConnectionString) + oConnection.Open() + oConnection.Close() + End Using + + Dim oResult = MessageBox.Show(STRING_CONNECTION_SUCCESSFUL, Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) + + If oResult = DialogResult.Yes Then + Dim oPlainTextConnectionString = $"Server={txtServerName.Text};Database={cmbDatabase.Text};User Id={txtUserName.Text};Password={txtPassword.Text};" + ConnectionString = MSSQLServer.EncryptConnectionString(oPlainTextConnectionString) + Close() + End If + Catch ex As Exception + Logger.Error(ex) + MsgBox("Error while connecting to Database", MsgBoxStyle.Critical, Text) + End Try + End Sub + + Private Sub frmSQLConfig_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing + If ConnectionString <> String.Empty Then + DialogResult = DialogResult.OK + Else + DialogResult = DialogResult.Cancel + End If + End Sub +End Class \ No newline at end of file