├── .gitattributes ├── .gitignore ├── Data Connection Dialog.docx ├── License.txt ├── ReadMe.txt └── Source ├── ConnectionDialog.sln ├── ConnectionUI ├── IDataConnectionProperties.cs ├── IDataConnectionUIControl.cs └── Microsoft.Data.ConnectionUI.csproj ├── ConnectionUIDialog ├── AccessConnectionUIControl.Designer.cs ├── AccessConnectionUIControl.cs ├── AccessConnectionUIControl.resx ├── AddPropertyDialog.Designer.cs ├── AddPropertyDialog.cs ├── AddPropertyDialog.resx ├── AdoDotNetConnectionProperties.cs ├── ContextHelpEventArgs.cs ├── DataConnectionAdvancedDialog.Designer.cs ├── DataConnectionAdvancedDialog.cs ├── DataConnectionAdvancedDialog.resx ├── DataConnectionDialog.Designer.cs ├── DataConnectionDialog.cs ├── DataConnectionDialog.resx ├── DataConnectionDialogContext.cs ├── DataConnectionSourceDialog.Designer.cs ├── DataConnectionSourceDialog.cs ├── DataConnectionSourceDialog.resx ├── DataProvider.cs ├── DataSource.cs ├── DynamicPropertyDescriptor.cs ├── HelpUtils.cs ├── LayoutUtils.cs ├── Microsoft.Data.ConnectionUI.Dialog.csproj ├── NativeMethods.cs ├── OdbcConnectionProperties.cs ├── OdbcConnectionUIControl.Designer.cs ├── OdbcConnectionUIControl.cs ├── OdbcConnectionUIControl.resx ├── OleDBConnectionProperties.cs ├── OleDBConnectionUIControl.Designer.cs ├── OleDBConnectionUIControl.cs ├── OleDBConnectionUIControl.resx ├── OracleConnectionProperties.cs ├── OracleConnectionUIControl.Designer.cs ├── OracleConnectionUIControl.cs ├── OracleConnectionUIControl.resx ├── RTLAwareMessageBox.cs ├── SqlConnectionProperties.cs ├── SqlConnectionUIControl.Designer.cs ├── SqlConnectionUIControl.cs ├── SqlConnectionUIControl.resx ├── SqlExpressConnectionUIControl.Designer.cs ├── SqlExpressConnectionUIControl.cs ├── SqlExpressConnectionUIControl.resx ├── Strings.Designer.cs ├── Strings.resx └── UserPreferencedChangedHandler.cs ├── References └── Microsoft.SqlServerCe.Client.dll ├── Sample.VB ├── DataConnectionConfiguration.vb ├── IDataConnectionConfiguration.vb ├── Microsoft.Data.ConnectionUI.Sample.VB.vbproj ├── My Project │ ├── Application.Designer.vb │ ├── Application.myapp │ ├── AssemblyInfo.vb │ ├── Resources.Designer.vb │ ├── Resources.resx │ ├── Settings.Designer.vb │ └── Settings.settings └── Sample.vb ├── Sample ├── DataConnectionConfiguration.cs ├── IDataConnectionConfiguration.cs ├── Microsoft.Data.ConnectionUI.Sample.csproj ├── Properties │ └── AssemblyInfo.cs ├── Sample.cs ├── app.config └── app.manifest └── SqlCeDataProvider ├── Microsoft.Data.ConnectionUI.SqlCeDataProvider.csproj ├── Properties └── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── SqlCeConnection.cs ├── SqlCeConnectionProperties.cs ├── SqlCeConnectionUIControl.Designer.cs ├── SqlCeConnectionUIControl.cs └── SqlCeConnectionUIControl.resx /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | *.sln merge=union 7 | *.csproj merge=union 8 | *.vbproj merge=union 9 | *.fsproj merge=union 10 | *.dbproj merge=union 11 | 12 | # Standard to msysgit 13 | *.doc diff=astextplain 14 | *.DOC diff=astextplain 15 | *.docx diff=astextplain 16 | *.DOCX diff=astextplain 17 | *.dot diff=astextplain 18 | *.DOT diff=astextplain 19 | *.pdf diff=astextplain 20 | *.PDF diff=astextplain 21 | *.rtf diff=astextplain 22 | *.RTF diff=astextplain 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Thumbs.db 2 | *.user 3 | *.suo 4 | [Bb]in/ 5 | [Oo]bj/ 6 | -------------------------------------------------------------------------------- /Data Connection Dialog.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kjbartel/ConnectionDialog/3eb8a29fe3103288ea5084140244e482deb16a13/Data Connection Dialog.docx -------------------------------------------------------------------------------- /License.txt: -------------------------------------------------------------------------------- 1 | Microsoft Limited Public License (MS-LPL) 2 | 3 | This license governs use of the accompanying software. If you use the software, you accept this license. If you do not accept the license, do not use the software. 4 | 5 | 1. Definitions 6 | The terms "reproduce," "reproduction," "derivative works," and "distribution" have the same meaning here as under U.S. copyright law. 7 | A "contribution" is the original software, or any additions or changes to the software. 8 | A "contributor" is any person that distributes its contribution under this license. 9 | "Licensed patents" are a contributor’s patent claims that read directly on its contribution. 10 | 11 | 2. Grant of Rights 12 | (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create. 13 | (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3, each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software. 14 | 15 | 3. Conditions and Limitations 16 | (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks. 17 | (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software, your patent license from such contributor to the software ends automatically. 18 | (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution notices that are present in the software. 19 | (D) If you distribute any portion of the software in source code form, you may do so only under this license by including a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object code form, you may only do so under a license that complies with this license. 20 | (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular purpose and non-infringement. 21 | (F) Platform Limitation- The licenses granted in sections 2(A) & 2(B) extend only to the software or derivative works that you create that run on a Microsoft Windows operating system product. -------------------------------------------------------------------------------- /ReadMe.txt: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Connection Dialog 2 | ========================================= 3 | This is the Visual Studio connection dialog originally released by Microsoft but no longer available on their website. 4 | 5 | Details of the dialog are outlined in this msdn blog entry: 6 | http://blogs.msdn.com/b/vsdata/archive/2010/02/02/data-connection-dialog-source-code-is-released-on-code-gallery.aspx 7 | The original project site can also be viewed via the Internet Archive's Way Back Machine: 8 | https://web.archive.org/web/20100216143342/http://code.msdn.microsoft.com/Connection 9 | 10 | If all you need is the prebuilt dialog then use nuget: 11 | https://www.nuget.org/packages/DataConnectionDialog/ 12 | 13 | This source is also available in the "Tools" directory of the nuget package. The project files of the source here have been updated so that they may be built in Visual Studio 2013. -------------------------------------------------------------------------------- /Source/ConnectionDialog.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.30501.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.ConnectionUI", "ConnectionUI\Microsoft.Data.ConnectionUI.csproj", "{139729CD-0F06-48E8-9F4A-08E78BB6575F}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.ConnectionUI.Dialog", "ConnectionUIDialog\Microsoft.Data.ConnectionUI.Dialog.csproj", "{05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.ConnectionUI.Sample", "Sample\Microsoft.Data.ConnectionUI.Sample.csproj", "{444AC953-5861-49CA-B491-9EB8A1C6CE24}" 11 | EndProject 12 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Data.ConnectionUI.SqlCeDataProvider", "SqlCeDataProvider\Microsoft.Data.ConnectionUI.SqlCeDataProvider.csproj", "{1CC9D080-C06D-4202-A14B-14A9CC7F7F31}" 13 | EndProject 14 | Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Microsoft.Data.ConnectionUI.Sample.VB", "Sample.VB\Microsoft.Data.ConnectionUI.Sample.VB.vbproj", "{CF22916C-6B3C-4D67-AD2E-94A730526539}" 15 | EndProject 16 | Global 17 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 18 | Debug|Any CPU = Debug|Any CPU 19 | Debug|x64 = Debug|x64 20 | Debug|x86 = Debug|x86 21 | Release|Any CPU = Release|Any CPU 22 | Release|x64 = Release|x64 23 | Release|x86 = Release|x86 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Debug|x64.ActiveCfg = Debug|Any CPU 29 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Debug|x64.Build.0 = Debug|Any CPU 30 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Debug|x86.ActiveCfg = Debug|Any CPU 31 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Debug|x86.Build.0 = Debug|Any CPU 32 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Release|Any CPU.ActiveCfg = Debug|Any CPU 33 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Release|Any CPU.Build.0 = Debug|Any CPU 34 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Release|x64.ActiveCfg = Debug|x64 35 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Release|x64.Build.0 = Debug|x64 36 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Release|x86.ActiveCfg = Debug|x86 37 | {139729CD-0F06-48E8-9F4A-08E78BB6575F}.Release|x86.Build.0 = Debug|x86 38 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Debug|x64.ActiveCfg = Debug|Any CPU 41 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Debug|x64.Build.0 = Debug|Any CPU 42 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Debug|x86.ActiveCfg = Debug|Any CPU 43 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Debug|x86.Build.0 = Debug|Any CPU 44 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Release|Any CPU.ActiveCfg = Debug|Any CPU 45 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Release|Any CPU.Build.0 = Debug|Any CPU 46 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Release|x64.ActiveCfg = Debug|x64 47 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Release|x64.Build.0 = Debug|x64 48 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Release|x86.ActiveCfg = Debug|x86 49 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA}.Release|x86.Build.0 = Debug|x86 50 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Debug|x64.ActiveCfg = Debug|Any CPU 53 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Debug|x64.Build.0 = Debug|Any CPU 54 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Debug|x86.ActiveCfg = Debug|x86 55 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Debug|x86.Build.0 = Debug|x86 56 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Release|Any CPU.ActiveCfg = Release|Any CPU 57 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Release|Any CPU.Build.0 = Release|Any CPU 58 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Release|x64.ActiveCfg = Release|x64 59 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Release|x64.Build.0 = Release|x64 60 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Release|x86.ActiveCfg = Release|x86 61 | {444AC953-5861-49CA-B491-9EB8A1C6CE24}.Release|x86.Build.0 = Release|x86 62 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 63 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Debug|Any CPU.Build.0 = Debug|Any CPU 64 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Debug|x64.ActiveCfg = Debug|Any CPU 65 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Debug|x64.Build.0 = Debug|Any CPU 66 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Debug|x86.ActiveCfg = Debug|x86 67 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Debug|x86.Build.0 = Debug|x86 68 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Release|Any CPU.ActiveCfg = Release|Any CPU 69 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Release|Any CPU.Build.0 = Release|Any CPU 70 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Release|x64.ActiveCfg = Release|x64 71 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Release|x64.Build.0 = Release|x64 72 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Release|x86.ActiveCfg = Release|x86 73 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31}.Release|x86.Build.0 = Release|x86 74 | {CF22916C-6B3C-4D67-AD2E-94A730526539}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 75 | {CF22916C-6B3C-4D67-AD2E-94A730526539}.Debug|Any CPU.Build.0 = Debug|Any CPU 76 | {CF22916C-6B3C-4D67-AD2E-94A730526539}.Debug|x64.ActiveCfg = Debug|Any CPU 77 | {CF22916C-6B3C-4D67-AD2E-94A730526539}.Debug|x86.ActiveCfg = Debug|Any CPU 78 | {CF22916C-6B3C-4D67-AD2E-94A730526539}.Release|Any CPU.ActiveCfg = Release|Any CPU 79 | {CF22916C-6B3C-4D67-AD2E-94A730526539}.Release|Any CPU.Build.0 = Release|Any CPU 80 | {CF22916C-6B3C-4D67-AD2E-94A730526539}.Release|x64.ActiveCfg = Release|Any CPU 81 | {CF22916C-6B3C-4D67-AD2E-94A730526539}.Release|x86.ActiveCfg = Release|Any CPU 82 | EndGlobalSection 83 | GlobalSection(SolutionProperties) = preSolution 84 | HideSolutionNode = FALSE 85 | EndGlobalSection 86 | EndGlobal 87 | -------------------------------------------------------------------------------- /Source/ConnectionUI/IDataConnectionProperties.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | using System; 7 | 8 | 9 | namespace Microsoft.Data.ConnectionUI 10 | { 11 | public interface IDataConnectionProperties 12 | { 13 | void Add(string propertyName); 14 | bool Contains(string propertyName); 15 | bool IsComplete { get; } 16 | bool IsExtensible { get; } 17 | void Parse(string s); 18 | event EventHandler PropertyChanged; 19 | void Remove(string propertyName); 20 | void Reset(); 21 | void Reset(string propertyName); 22 | void Test(); 23 | object this[string propertyName] { get; set; } 24 | string ToDisplayString(); 25 | string ToFullString(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Source/ConnectionUI/IDataConnectionUIControl.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | 9 | namespace Microsoft.Data.ConnectionUI 10 | { 11 | public interface IDataConnectionUIControl 12 | { 13 | void Initialize(IDataConnectionProperties connectionProperties); 14 | void LoadProperties(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Source/ConnectionUI/Microsoft.Data.ConnectionUI.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | true 7 | Microsoft.Data.ConnectionUI 8 | Library 9 | bin\Debug\ 10 | 11 | 12 | {139729CD-0F06-48E8-9F4A-08E78BB6575F} 13 | v3.5 14 | Microsoft.Data.ConnectionUI 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | true 23 | bin\x86\Debug\ 24 | x86 25 | true 26 | GlobalSuppressions.cs 27 | 28 | 29 | true 30 | bin\x64\Debug\ 31 | x64 32 | true 33 | GlobalSuppressions.cs 34 | 35 | 36 | 37 | 38 | 39 | 3.5 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/AccessConnectionUIControl.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Data.ConnectionUI 2 | { 3 | public partial class AccessConnectionUIControl 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | protected override void Dispose(bool disposing) 14 | { 15 | if (disposing && (components != null)) 16 | { 17 | components.Dispose(); 18 | } 19 | base.Dispose(disposing); 20 | } 21 | 22 | #region Component Designer generated code 23 | 24 | /// 25 | /// Required method for Designer support - do not modify 26 | /// the contents of this method with the code editor. 27 | /// 28 | private void InitializeComponent() 29 | { 30 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AccessConnectionUIControl)); 31 | this.databaseFileLabel = new System.Windows.Forms.Label(); 32 | this.databaseFileTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 33 | this.databaseFileTextBox = new System.Windows.Forms.TextBox(); 34 | this.browseButton = new System.Windows.Forms.Button(); 35 | this.logonGroupBox = new System.Windows.Forms.GroupBox(); 36 | this.loginTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 37 | this.userNameLabel = new System.Windows.Forms.Label(); 38 | this.userNameTextBox = new System.Windows.Forms.TextBox(); 39 | this.passwordLabel = new System.Windows.Forms.Label(); 40 | this.passwordTextBox = new System.Windows.Forms.TextBox(); 41 | this.savePasswordCheckBox = new System.Windows.Forms.CheckBox(); 42 | this.databaseFileTableLayoutPanel.SuspendLayout(); 43 | this.logonGroupBox.SuspendLayout(); 44 | this.loginTableLayoutPanel.SuspendLayout(); 45 | this.SuspendLayout(); 46 | // 47 | // databaseFileLabel 48 | // 49 | resources.ApplyResources(this.databaseFileLabel, "databaseFileLabel"); 50 | this.databaseFileLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 51 | this.databaseFileLabel.Name = "databaseFileLabel"; 52 | // 53 | // databaseFileTableLayoutPanel 54 | // 55 | resources.ApplyResources(this.databaseFileTableLayoutPanel, "databaseFileTableLayoutPanel"); 56 | this.databaseFileTableLayoutPanel.Controls.Add(this.databaseFileTextBox, 0, 0); 57 | this.databaseFileTableLayoutPanel.Controls.Add(this.browseButton, 1, 0); 58 | this.databaseFileTableLayoutPanel.Name = "databaseFileTableLayoutPanel"; 59 | // 60 | // databaseFileTextBox 61 | // 62 | resources.ApplyResources(this.databaseFileTextBox, "databaseFileTextBox"); 63 | this.databaseFileTextBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; 64 | this.databaseFileTextBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.FileSystem; 65 | this.databaseFileTextBox.Name = "databaseFileTextBox"; 66 | this.databaseFileTextBox.Leave += new System.EventHandler(this.TrimControlText); 67 | this.databaseFileTextBox.TextChanged += new System.EventHandler(this.SetDatabaseFile); 68 | // 69 | // browseButton 70 | // 71 | resources.ApplyResources(this.browseButton, "browseButton"); 72 | this.browseButton.Name = "browseButton"; 73 | this.browseButton.Click += new System.EventHandler(this.Browse); 74 | // 75 | // logonGroupBox 76 | // 77 | resources.ApplyResources(this.logonGroupBox, "logonGroupBox"); 78 | this.logonGroupBox.Controls.Add(this.loginTableLayoutPanel); 79 | this.logonGroupBox.FlatStyle = System.Windows.Forms.FlatStyle.System; 80 | this.logonGroupBox.Name = "logonGroupBox"; 81 | this.logonGroupBox.TabStop = false; 82 | // 83 | // loginTableLayoutPanel 84 | // 85 | resources.ApplyResources(this.loginTableLayoutPanel, "loginTableLayoutPanel"); 86 | this.loginTableLayoutPanel.Controls.Add(this.userNameLabel, 0, 0); 87 | this.loginTableLayoutPanel.Controls.Add(this.userNameTextBox, 1, 0); 88 | this.loginTableLayoutPanel.Controls.Add(this.passwordLabel, 0, 1); 89 | this.loginTableLayoutPanel.Controls.Add(this.passwordTextBox, 1, 1); 90 | this.loginTableLayoutPanel.Controls.Add(this.savePasswordCheckBox, 1, 2); 91 | this.loginTableLayoutPanel.Name = "loginTableLayoutPanel"; 92 | // 93 | // userNameLabel 94 | // 95 | resources.ApplyResources(this.userNameLabel, "userNameLabel"); 96 | this.userNameLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 97 | this.userNameLabel.Name = "userNameLabel"; 98 | // 99 | // userNameTextBox 100 | // 101 | resources.ApplyResources(this.userNameTextBox, "userNameTextBox"); 102 | this.userNameTextBox.Name = "userNameTextBox"; 103 | this.userNameTextBox.Leave += new System.EventHandler(this.TrimControlText); 104 | this.userNameTextBox.TextChanged += new System.EventHandler(this.SetUserName); 105 | // 106 | // passwordLabel 107 | // 108 | resources.ApplyResources(this.passwordLabel, "passwordLabel"); 109 | this.passwordLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 110 | this.passwordLabel.Name = "passwordLabel"; 111 | // 112 | // passwordTextBox 113 | // 114 | resources.ApplyResources(this.passwordTextBox, "passwordTextBox"); 115 | this.passwordTextBox.Name = "passwordTextBox"; 116 | this.passwordTextBox.UseSystemPasswordChar = true; 117 | this.passwordTextBox.TextChanged += new System.EventHandler(this.SetPassword); 118 | // 119 | // savePasswordCheckBox 120 | // 121 | resources.ApplyResources(this.savePasswordCheckBox, "savePasswordCheckBox"); 122 | this.savePasswordCheckBox.Name = "savePasswordCheckBox"; 123 | this.savePasswordCheckBox.CheckedChanged += new System.EventHandler(this.SetSavePassword); 124 | // 125 | // AccessConnectionUIControl 126 | // 127 | resources.ApplyResources(this, "$this"); 128 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 129 | this.Controls.Add(this.logonGroupBox); 130 | this.Controls.Add(this.databaseFileTableLayoutPanel); 131 | this.Controls.Add(this.databaseFileLabel); 132 | this.MinimumSize = new System.Drawing.Size(300, 148); 133 | this.Name = "AccessConnectionUIControl"; 134 | this.databaseFileTableLayoutPanel.ResumeLayout(false); 135 | this.databaseFileTableLayoutPanel.PerformLayout(); 136 | this.logonGroupBox.ResumeLayout(false); 137 | this.logonGroupBox.PerformLayout(); 138 | this.loginTableLayoutPanel.ResumeLayout(false); 139 | this.loginTableLayoutPanel.PerformLayout(); 140 | this.ResumeLayout(false); 141 | this.PerformLayout(); 142 | 143 | } 144 | 145 | #endregion 146 | 147 | private System.Windows.Forms.Label databaseFileLabel; 148 | private System.Windows.Forms.TableLayoutPanel databaseFileTableLayoutPanel; 149 | private System.Windows.Forms.TextBox databaseFileTextBox; 150 | private System.Windows.Forms.Button browseButton; 151 | private System.Windows.Forms.GroupBox logonGroupBox; 152 | private System.Windows.Forms.TableLayoutPanel loginTableLayoutPanel; 153 | private System.Windows.Forms.Label userNameLabel; 154 | private System.Windows.Forms.TextBox userNameTextBox; 155 | private System.Windows.Forms.Label passwordLabel; 156 | private System.Windows.Forms.TextBox passwordTextBox; 157 | private System.Windows.Forms.CheckBox savePasswordCheckBox; 158 | 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/AccessConnectionUIControl.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Drawing; 9 | using System.Diagnostics; 10 | using System.Windows.Forms; 11 | 12 | namespace Microsoft.Data.ConnectionUI 13 | { 14 | public partial class AccessConnectionUIControl : UserControl, IDataConnectionUIControl 15 | { 16 | public AccessConnectionUIControl() 17 | { 18 | InitializeComponent(); 19 | RightToLeft = RightToLeft.Inherit; 20 | 21 | int requiredHeight = LayoutUtils.GetPreferredCheckBoxHeight(savePasswordCheckBox); 22 | if (savePasswordCheckBox.Height < requiredHeight) 23 | { 24 | savePasswordCheckBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom; 25 | loginTableLayoutPanel.Height += loginTableLayoutPanel.Margin.Bottom; 26 | loginTableLayoutPanel.Margin = new Padding(loginTableLayoutPanel.Margin.Left, loginTableLayoutPanel.Margin.Top, loginTableLayoutPanel.Margin.Right, 0); 27 | } 28 | } 29 | 30 | public void Initialize(IDataConnectionProperties connectionProperties) 31 | { 32 | if (connectionProperties == null) 33 | { 34 | throw new ArgumentNullException("connectionProperties"); 35 | } 36 | 37 | if (!(connectionProperties is OleDBAccessConnectionProperties)) 38 | { 39 | throw new ArgumentException(Strings.AccessConnectionUIControl_InvalidConnectionProperties); 40 | } 41 | 42 | if (connectionProperties is OdbcConnectionProperties) 43 | { 44 | // ODBC does not support saving the password 45 | savePasswordCheckBox.Enabled = false; 46 | } 47 | 48 | _connectionProperties = connectionProperties; 49 | } 50 | 51 | public void LoadProperties() 52 | { 53 | _loading = true; 54 | 55 | databaseFileTextBox.Text = Properties[DatabaseFileProperty] as string; 56 | userNameTextBox.Text = Properties[UserNameProperty] as string; 57 | if (userNameTextBox.Text.Length == 0) 58 | { 59 | userNameTextBox.Text = "Admin"; 60 | } 61 | passwordTextBox.Text = Properties[PasswordProperty] as string; 62 | if (!(Properties is OdbcConnectionProperties)) 63 | { 64 | savePasswordCheckBox.Checked = (bool)Properties["Persist Security Info"]; 65 | } 66 | else 67 | { 68 | savePasswordCheckBox.Checked = false; 69 | } 70 | 71 | _loading = false; 72 | } 73 | 74 | // Simulate RTL mirroring 75 | protected override void OnRightToLeftChanged(EventArgs e) 76 | { 77 | base.OnRightToLeftChanged(e); 78 | if (ParentForm != null && 79 | ParentForm.RightToLeftLayout == true && 80 | RightToLeft == RightToLeft.Yes) 81 | { 82 | LayoutUtils.MirrorControl(databaseFileLabel, databaseFileTableLayoutPanel); 83 | } 84 | else 85 | { 86 | LayoutUtils.UnmirrorControl(databaseFileLabel, databaseFileTableLayoutPanel); 87 | } 88 | } 89 | 90 | protected override void ScaleControl(SizeF factor, BoundsSpecified specified) 91 | { 92 | Size baseSize = Size; 93 | MinimumSize = Size.Empty; 94 | base.ScaleControl(factor, specified); 95 | MinimumSize = new Size( 96 | (int)Math.Round((float)baseSize.Width * factor.Width), 97 | (int)Math.Round((float)baseSize.Height * factor.Height)); 98 | } 99 | 100 | protected override void OnParentChanged(EventArgs e) 101 | { 102 | base.OnParentChanged(e); 103 | if (Parent == null) 104 | { 105 | OnFontChanged(e); 106 | } 107 | } 108 | 109 | private void SetDatabaseFile(object sender, System.EventArgs e) 110 | { 111 | if (!_loading) 112 | { 113 | Properties[DatabaseFileProperty] = (databaseFileTextBox.Text.Trim().Length > 0) ? databaseFileTextBox.Text.Trim() : null; 114 | } 115 | } 116 | 117 | private void Browse(object sender, System.EventArgs e) 118 | { 119 | OpenFileDialog fileDialog = new OpenFileDialog(); 120 | fileDialog.Title = Strings.AccessConnectionUIControl_BrowseFileTitle; 121 | fileDialog.Multiselect = false; 122 | fileDialog.RestoreDirectory = true; 123 | fileDialog.Filter = Strings.AccessConnectionUIControl_BrowseFileFilter; 124 | fileDialog.DefaultExt = Strings.AccessConnectionUIControl_BrowseFileDefaultExt; 125 | if (this.Container != null) 126 | { 127 | this.Container.Add(fileDialog); 128 | } 129 | try 130 | { 131 | DialogResult result = fileDialog.ShowDialog(ParentForm); 132 | if (result == DialogResult.OK) 133 | { 134 | databaseFileTextBox.Text = fileDialog.FileName.Trim(); 135 | } 136 | } 137 | finally 138 | { 139 | if (this.Container != null) 140 | { 141 | this.Container.Remove(fileDialog); 142 | } 143 | fileDialog.Dispose(); 144 | } 145 | } 146 | 147 | private void SetUserName(object sender, EventArgs e) 148 | { 149 | if (!_loading) 150 | { 151 | Properties[UserNameProperty] = (userNameTextBox.Text.Trim().Length > 0) ? userNameTextBox.Text.Trim() : null; 152 | if ((Properties[UserNameProperty] as string).Equals("Admin")) 153 | { 154 | Properties[UserNameProperty] = null; 155 | } 156 | } 157 | } 158 | 159 | private void SetPassword(object sender, EventArgs e) 160 | { 161 | if (!_loading) 162 | { 163 | Properties[PasswordProperty] = (passwordTextBox.Text.Length > 0) ? passwordTextBox.Text : null; 164 | passwordTextBox.Text = passwordTextBox.Text; // forces reselection of all text 165 | } 166 | } 167 | 168 | private void SetSavePassword(object sender, EventArgs e) 169 | { 170 | if (!_loading) 171 | { 172 | Properties["Persist Security Info"] = savePasswordCheckBox.Checked; 173 | } 174 | } 175 | 176 | private void TrimControlText(object sender, EventArgs e) 177 | { 178 | Control c = sender as Control; 179 | c.Text = c.Text.Trim(); 180 | } 181 | 182 | private string DatabaseFileProperty 183 | { 184 | get 185 | { 186 | if (!(Properties is OdbcConnectionProperties)) 187 | { 188 | return "Data Source"; 189 | } 190 | else 191 | { 192 | return "DBQ"; 193 | } 194 | } 195 | } 196 | 197 | private string UserNameProperty 198 | { 199 | get 200 | { 201 | if (!(Properties is OdbcConnectionProperties)) 202 | { 203 | return "User ID"; 204 | } 205 | else 206 | { 207 | return "UID"; 208 | } 209 | } 210 | } 211 | 212 | private string PasswordProperty 213 | { 214 | get 215 | { 216 | if (!(Properties is OdbcConnectionProperties)) 217 | { 218 | return "Jet OLEDB:Database Password"; 219 | } 220 | else 221 | { 222 | return "PWD"; 223 | } 224 | } 225 | } 226 | 227 | private IDataConnectionProperties Properties 228 | { 229 | get 230 | { 231 | return _connectionProperties; 232 | } 233 | } 234 | 235 | private bool _loading; 236 | private IDataConnectionProperties _connectionProperties; 237 | } 238 | } 239 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/AddPropertyDialog.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Data.ConnectionUI 2 | { 3 | partial class AddPropertyDialog 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | protected override void Dispose(bool disposing) 14 | { 15 | if (disposing && (components != null)) 16 | { 17 | components.Dispose(); 18 | } 19 | base.Dispose(disposing); 20 | } 21 | 22 | #region Windows Form Designer generated code 23 | 24 | /// 25 | /// Required method for Designer support - do not modify 26 | /// the contents of this method with the code editor. 27 | /// 28 | private void InitializeComponent() 29 | { 30 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AddPropertyDialog)); 31 | this.propertyLabel = new System.Windows.Forms.Label(); 32 | this.propertyTextBox = new System.Windows.Forms.TextBox(); 33 | this.buttonsTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 34 | this.okButton = new System.Windows.Forms.Button(); 35 | this.cancelButton = new System.Windows.Forms.Button(); 36 | this.buttonsTableLayoutPanel.SuspendLayout(); 37 | this.SuspendLayout(); 38 | // 39 | // propertyLabel 40 | // 41 | resources.ApplyResources(this.propertyLabel, "propertyLabel"); 42 | this.propertyLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 43 | this.propertyLabel.Name = "propertyLabel"; 44 | // 45 | // propertyTextBox 46 | // 47 | resources.ApplyResources(this.propertyTextBox, "propertyTextBox"); 48 | this.propertyTextBox.Name = "propertyTextBox"; 49 | this.propertyTextBox.TextChanged += new System.EventHandler(this.SetOkButtonStatus); 50 | // 51 | // buttonsTableLayoutPanel 52 | // 53 | resources.ApplyResources(this.buttonsTableLayoutPanel, "buttonsTableLayoutPanel"); 54 | this.buttonsTableLayoutPanel.Controls.Add(this.okButton, 0, 0); 55 | this.buttonsTableLayoutPanel.Controls.Add(this.cancelButton, 1, 0); 56 | this.buttonsTableLayoutPanel.Name = "buttonsTableLayoutPanel"; 57 | // 58 | // okButton 59 | // 60 | resources.ApplyResources(this.okButton, "okButton"); 61 | this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; 62 | this.okButton.MinimumSize = new System.Drawing.Size(75, 23); 63 | this.okButton.Name = "okButton"; 64 | // 65 | // cancelButton 66 | // 67 | resources.ApplyResources(this.cancelButton, "cancelButton"); 68 | this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; 69 | this.cancelButton.MinimumSize = new System.Drawing.Size(75, 23); 70 | this.cancelButton.Name = "cancelButton"; 71 | // 72 | // AddPropertyDialog 73 | // 74 | this.AcceptButton = this.okButton; 75 | resources.ApplyResources(this, "$this"); 76 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 77 | this.CancelButton = this.cancelButton; 78 | this.Controls.Add(this.buttonsTableLayoutPanel); 79 | this.Controls.Add(this.propertyTextBox); 80 | this.Controls.Add(this.propertyLabel); 81 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 82 | this.HelpButton = true; 83 | this.MaximizeBox = false; 84 | this.MinimizeBox = false; 85 | this.Name = "AddPropertyDialog"; 86 | this.ShowInTaskbar = false; 87 | this.buttonsTableLayoutPanel.ResumeLayout(false); 88 | this.buttonsTableLayoutPanel.PerformLayout(); 89 | this.ResumeLayout(false); 90 | this.PerformLayout(); 91 | 92 | } 93 | 94 | #endregion 95 | 96 | private System.Windows.Forms.Label propertyLabel; 97 | private System.Windows.Forms.TextBox propertyTextBox; 98 | private System.Windows.Forms.TableLayoutPanel buttonsTableLayoutPanel; 99 | private System.Windows.Forms.Button okButton; 100 | private System.Windows.Forms.Button cancelButton; 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/AddPropertyDialog.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Drawing; 9 | using System.Diagnostics; 10 | using System.Windows.Forms; 11 | 12 | namespace Microsoft.Data.ConnectionUI 13 | { 14 | internal partial class AddPropertyDialog : Form 15 | { 16 | public AddPropertyDialog() 17 | { 18 | InitializeComponent(); 19 | 20 | // Make sure we handle a user preference change 21 | if (this.components == null) 22 | { 23 | this.components = new System.ComponentModel.Container(); 24 | } 25 | this.components.Add(new UserPreferenceChangedHandler(this)); 26 | } 27 | 28 | public AddPropertyDialog(DataConnectionDialog mainDialog) 29 | : this() 30 | { 31 | Debug.Assert(mainDialog != null); 32 | 33 | _mainDialog = mainDialog; 34 | } 35 | 36 | public string PropertyName 37 | { 38 | get 39 | { 40 | return propertyTextBox.Text; 41 | } 42 | } 43 | 44 | protected override void OnFontChanged(EventArgs e) 45 | { 46 | base.OnFontChanged(e); 47 | 48 | this.propertyTextBox.Width = 49 | this.buttonsTableLayoutPanel.Right - 50 | this.propertyTextBox.Left; 51 | 52 | // Resize the dialog appropriately so that OK/Cancel buttons fit 53 | int preferredClientWidth = 54 | this.Padding.Left + 55 | this.buttonsTableLayoutPanel.Margin.Left + 56 | this.buttonsTableLayoutPanel.Width + 57 | this.buttonsTableLayoutPanel.Margin.Right + 58 | this.Padding.Right; 59 | if (ClientSize.Width < preferredClientWidth) 60 | { 61 | ClientSize = new Size(preferredClientWidth, ClientSize.Height); 62 | } 63 | } 64 | 65 | protected override void OnHelpRequested(HelpEventArgs hevent) 66 | { 67 | // Get the active control 68 | Control activeControl = HelpUtils.GetActiveControl(this); 69 | 70 | // Figure out the context 71 | DataConnectionDialogContext context = DataConnectionDialogContext.AddProperty; 72 | if (activeControl == propertyTextBox) 73 | { 74 | context = DataConnectionDialogContext.AddPropertyTextBox; 75 | } 76 | if (activeControl == okButton) 77 | { 78 | context = DataConnectionDialogContext.AddPropertyOkButton; 79 | } 80 | if (activeControl == cancelButton) 81 | { 82 | context = DataConnectionDialogContext.AddPropertyCancelButton; 83 | } 84 | 85 | // Call OnContextHelpRequested 86 | ContextHelpEventArgs e = new ContextHelpEventArgs(context, hevent.MousePos); 87 | _mainDialog.OnContextHelpRequested(e); 88 | hevent.Handled = e.Handled; 89 | if (!e.Handled) 90 | { 91 | base.OnHelpRequested(hevent); 92 | } 93 | } 94 | 95 | protected override void WndProc(ref Message m) 96 | { 97 | if (_mainDialog.TranslateHelpButton && HelpUtils.IsContextHelpMessage(ref m)) 98 | { 99 | // Force the ? in the title bar to invoke the help topic 100 | HelpUtils.TranslateContextHelpMessage(this, ref m); 101 | } 102 | base.WndProc(ref m); 103 | } 104 | 105 | private void SetOkButtonStatus(object sender, EventArgs e) 106 | { 107 | okButton.Enabled = (propertyTextBox.Text.Trim().Length > 0); 108 | } 109 | 110 | private DataConnectionDialog _mainDialog; 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/ContextHelpEventArgs.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Drawing; 9 | using System.Windows.Forms; 10 | 11 | namespace Microsoft.Data.ConnectionUI 12 | { 13 | public class ContextHelpEventArgs : HelpEventArgs 14 | { 15 | public ContextHelpEventArgs(DataConnectionDialogContext context, Point mousePos) : base(mousePos) 16 | { 17 | _context = context; 18 | } 19 | 20 | public DataConnectionDialogContext Context 21 | { 22 | get 23 | { 24 | return _context; 25 | } 26 | } 27 | 28 | private DataConnectionDialogContext _context; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/DataConnectionAdvancedDialog.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Data.ConnectionUI 2 | { 3 | partial class DataConnectionAdvancedDialog 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | protected override void Dispose(bool disposing) 14 | { 15 | if (disposing && (components != null)) 16 | { 17 | components.Dispose(); 18 | } 19 | base.Dispose(disposing); 20 | } 21 | 22 | #region Windows Form Designer generated code 23 | 24 | /// 25 | /// Required method for Designer support - do not modify 26 | /// the contents of this method with the code editor. 27 | /// 28 | private void InitializeComponent() 29 | { 30 | this.components = new System.ComponentModel.Container(); 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DataConnectionAdvancedDialog)); 32 | this.propertyGrid = new Microsoft.Data.ConnectionUI.DataConnectionAdvancedDialog.SpecializedPropertyGrid(); 33 | this.textBox = new System.Windows.Forms.TextBox(); 34 | this.buttonsTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 35 | this.okButton = new System.Windows.Forms.Button(); 36 | this.cancelButton = new System.Windows.Forms.Button(); 37 | this.buttonsTableLayoutPanel.SuspendLayout(); 38 | this.SuspendLayout(); 39 | // 40 | // propertyGrid 41 | // 42 | resources.ApplyResources(this.propertyGrid, "propertyGrid"); 43 | this.propertyGrid.CommandsActiveLinkColor = System.Drawing.SystemColors.ActiveCaption; 44 | this.propertyGrid.CommandsDisabledLinkColor = System.Drawing.SystemColors.ControlDark; 45 | this.propertyGrid.CommandsLinkColor = System.Drawing.SystemColors.ActiveCaption; 46 | this.propertyGrid.MinimumSize = new System.Drawing.Size(270, 250); 47 | this.propertyGrid.Name = "propertyGrid"; 48 | this.propertyGrid.PropertyValueChanged += new System.Windows.Forms.PropertyValueChangedEventHandler(this.SetTextBox); 49 | // 50 | // textBox 51 | // 52 | resources.ApplyResources(this.textBox, "textBox"); 53 | this.textBox.Name = "textBox"; 54 | this.textBox.ReadOnly = true; 55 | // 56 | // buttonsTableLayoutPanel 57 | // 58 | resources.ApplyResources(this.buttonsTableLayoutPanel, "buttonsTableLayoutPanel"); 59 | this.buttonsTableLayoutPanel.Controls.Add(this.okButton, 0, 0); 60 | this.buttonsTableLayoutPanel.Controls.Add(this.cancelButton, 1, 0); 61 | this.buttonsTableLayoutPanel.Name = "buttonsTableLayoutPanel"; 62 | // 63 | // okButton 64 | // 65 | resources.ApplyResources(this.okButton, "okButton"); 66 | this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; 67 | this.okButton.MinimumSize = new System.Drawing.Size(75, 23); 68 | this.okButton.Name = "okButton"; 69 | // 70 | // cancelButton 71 | // 72 | resources.ApplyResources(this.cancelButton, "cancelButton"); 73 | this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; 74 | this.cancelButton.MinimumSize = new System.Drawing.Size(75, 23); 75 | this.cancelButton.Name = "cancelButton"; 76 | this.cancelButton.Click += new System.EventHandler(this.RevertProperties); 77 | // 78 | // DataConnectionAdvancedDialog 79 | // 80 | this.AcceptButton = this.okButton; 81 | resources.ApplyResources(this, "$this"); 82 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 83 | this.CancelButton = this.cancelButton; 84 | this.Controls.Add(this.buttonsTableLayoutPanel); 85 | this.Controls.Add(this.textBox); 86 | this.Controls.Add(this.propertyGrid); 87 | this.HelpButton = true; 88 | this.MaximizeBox = false; 89 | this.MinimizeBox = false; 90 | this.Name = "DataConnectionAdvancedDialog"; 91 | this.ShowIcon = false; 92 | this.ShowInTaskbar = false; 93 | this.buttonsTableLayoutPanel.ResumeLayout(false); 94 | this.buttonsTableLayoutPanel.PerformLayout(); 95 | this.ResumeLayout(false); 96 | this.PerformLayout(); 97 | 98 | } 99 | 100 | #endregion 101 | 102 | private System.Windows.Forms.TextBox textBox; 103 | private System.Windows.Forms.TableLayoutPanel buttonsTableLayoutPanel; 104 | private System.Windows.Forms.Button okButton; 105 | private System.Windows.Forms.Button cancelButton; 106 | private DataConnectionAdvancedDialog.SpecializedPropertyGrid propertyGrid; 107 | 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/DataConnectionDialog.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Data.ConnectionUI 2 | { 3 | partial class DataConnectionDialog 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | protected override void Dispose(bool disposing) 14 | { 15 | if (disposing && (components != null)) 16 | { 17 | components.Dispose(); 18 | } 19 | base.Dispose(disposing); 20 | } 21 | 22 | #region Windows Form Designer generated code 23 | 24 | /// 25 | /// Required method for Designer support - do not modify 26 | /// the contents of this method with the code editor. 27 | /// 28 | private void InitializeComponent() 29 | { 30 | this.components = new System.ComponentModel.Container(); 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DataConnectionDialog)); 32 | this.dataSourceLabel = new System.Windows.Forms.Label(); 33 | this.dataSourceTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 34 | this.dataSourceTextBox = new System.Windows.Forms.TextBox(); 35 | this.changeDataSourceButton = new System.Windows.Forms.Button(); 36 | this.containerControl = new System.Windows.Forms.ContainerControl(); 37 | this.advancedButton = new System.Windows.Forms.Button(); 38 | this.separatorPanel = new System.Windows.Forms.Panel(); 39 | this.testConnectionButton = new System.Windows.Forms.Button(); 40 | this.buttonsTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 41 | this.acceptButton = new System.Windows.Forms.Button(); 42 | this.cancelButton = new System.Windows.Forms.Button(); 43 | this.dataProviderToolTip = new System.Windows.Forms.ToolTip(this.components); 44 | this.dataSourceTableLayoutPanel.SuspendLayout(); 45 | this.buttonsTableLayoutPanel.SuspendLayout(); 46 | this.SuspendLayout(); 47 | // 48 | // dataSourceLabel 49 | // 50 | resources.ApplyResources(this.dataSourceLabel, "dataSourceLabel"); 51 | this.dataSourceLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 52 | this.dataSourceLabel.Name = "dataSourceLabel"; 53 | // 54 | // dataSourceTableLayoutPanel 55 | // 56 | resources.ApplyResources(this.dataSourceTableLayoutPanel, "dataSourceTableLayoutPanel"); 57 | this.dataSourceTableLayoutPanel.Controls.Add(this.dataSourceTextBox, 0, 0); 58 | this.dataSourceTableLayoutPanel.Controls.Add(this.changeDataSourceButton, 1, 0); 59 | this.dataSourceTableLayoutPanel.Name = "dataSourceTableLayoutPanel"; 60 | // 61 | // dataSourceTextBox 62 | // 63 | resources.ApplyResources(this.dataSourceTextBox, "dataSourceTextBox"); 64 | this.dataSourceTextBox.Name = "dataSourceTextBox"; 65 | this.dataSourceTextBox.ReadOnly = true; 66 | // 67 | // changeDataSourceButton 68 | // 69 | resources.ApplyResources(this.changeDataSourceButton, "changeDataSourceButton"); 70 | this.changeDataSourceButton.MinimumSize = new System.Drawing.Size(75, 23); 71 | this.changeDataSourceButton.Name = "changeDataSourceButton"; 72 | this.changeDataSourceButton.Click += new System.EventHandler(this.ChangeDataSource); 73 | // 74 | // containerControl 75 | // 76 | resources.ApplyResources(this.containerControl, "containerControl"); 77 | this.containerControl.Name = "containerControl"; 78 | this.containerControl.SizeChanged += new System.EventHandler(this.SetConnectionUIControlDockStyle); 79 | // 80 | // advancedButton 81 | // 82 | resources.ApplyResources(this.advancedButton, "advancedButton"); 83 | this.advancedButton.MinimumSize = new System.Drawing.Size(81, 23); 84 | this.advancedButton.Name = "advancedButton"; 85 | this.advancedButton.Click += new System.EventHandler(this.ShowAdvanced); 86 | // 87 | // separatorPanel 88 | // 89 | resources.ApplyResources(this.separatorPanel, "separatorPanel"); 90 | this.separatorPanel.Name = "separatorPanel"; 91 | this.separatorPanel.Paint += new System.Windows.Forms.PaintEventHandler(this.PaintSeparator); 92 | // 93 | // testConnectionButton 94 | // 95 | resources.ApplyResources(this.testConnectionButton, "testConnectionButton"); 96 | this.testConnectionButton.MinimumSize = new System.Drawing.Size(101, 23); 97 | this.testConnectionButton.Name = "testConnectionButton"; 98 | this.testConnectionButton.Click += new System.EventHandler(this.TestConnection); 99 | // 100 | // buttonsTableLayoutPanel 101 | // 102 | resources.ApplyResources(this.buttonsTableLayoutPanel, "buttonsTableLayoutPanel"); 103 | this.buttonsTableLayoutPanel.Controls.Add(this.acceptButton, 0, 0); 104 | this.buttonsTableLayoutPanel.Controls.Add(this.cancelButton, 1, 0); 105 | this.buttonsTableLayoutPanel.Name = "buttonsTableLayoutPanel"; 106 | // 107 | // acceptButton 108 | // 109 | resources.ApplyResources(this.acceptButton, "acceptButton"); 110 | this.acceptButton.DialogResult = System.Windows.Forms.DialogResult.OK; 111 | this.acceptButton.MinimumSize = new System.Drawing.Size(75, 23); 112 | this.acceptButton.Name = "acceptButton"; 113 | this.acceptButton.Click += new System.EventHandler(this.HandleAccept); 114 | // 115 | // cancelButton 116 | // 117 | resources.ApplyResources(this.cancelButton, "cancelButton"); 118 | this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; 119 | this.cancelButton.MinimumSize = new System.Drawing.Size(75, 23); 120 | this.cancelButton.Name = "cancelButton"; 121 | // 122 | // DataConnectionDialog 123 | // 124 | this.AcceptButton = this.acceptButton; 125 | resources.ApplyResources(this, "$this"); 126 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 127 | this.CancelButton = this.cancelButton; 128 | this.Controls.Add(this.buttonsTableLayoutPanel); 129 | this.Controls.Add(this.testConnectionButton); 130 | this.Controls.Add(this.separatorPanel); 131 | this.Controls.Add(this.advancedButton); 132 | this.Controls.Add(this.containerControl); 133 | this.Controls.Add(this.dataSourceTableLayoutPanel); 134 | this.Controls.Add(this.dataSourceLabel); 135 | this.HelpButton = true; 136 | this.MaximizeBox = false; 137 | this.MinimizeBox = false; 138 | this.Name = "DataConnectionDialog"; 139 | this.ShowIcon = false; 140 | this.ShowInTaskbar = false; 141 | this.dataSourceTableLayoutPanel.ResumeLayout(false); 142 | this.dataSourceTableLayoutPanel.PerformLayout(); 143 | this.buttonsTableLayoutPanel.ResumeLayout(false); 144 | this.buttonsTableLayoutPanel.PerformLayout(); 145 | this.ResumeLayout(false); 146 | this.PerformLayout(); 147 | 148 | } 149 | 150 | #endregion 151 | 152 | private System.Windows.Forms.Label dataSourceLabel; 153 | private System.Windows.Forms.TableLayoutPanel dataSourceTableLayoutPanel; 154 | private System.Windows.Forms.TextBox dataSourceTextBox; 155 | private System.Windows.Forms.ToolTip dataProviderToolTip; 156 | private System.Windows.Forms.Button changeDataSourceButton; 157 | private System.Windows.Forms.ContainerControl containerControl; 158 | private System.Windows.Forms.Button advancedButton; 159 | private System.Windows.Forms.Panel separatorPanel; 160 | private System.Windows.Forms.Button testConnectionButton; 161 | private System.Windows.Forms.TableLayoutPanel buttonsTableLayoutPanel; 162 | private System.Windows.Forms.Button acceptButton; 163 | private System.Windows.Forms.Button cancelButton; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/DataConnectionDialogContext.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | 9 | namespace Microsoft.Data.ConnectionUI 10 | { 11 | public enum DataConnectionDialogContext 12 | { 13 | None = 0x00000000, 14 | 15 | Source = 0x01000000, 16 | SourceListBox = 0x01000001, 17 | SourceProviderComboBox = 0x01000002, 18 | SourceOkButton = 0x01000003, 19 | SourceCancelButton = 0x01000004, 20 | 21 | Main = 0x02000000, 22 | MainDataSourceTextBox = 0x02100001, 23 | MainChangeDataSourceButton = 0x02100002, 24 | MainConnectionUIControl = 0x02200000, 25 | MainSqlConnectionUIControl = 0x02200001, 26 | MainSqlFileConnectionUIControl = 0x02200002, 27 | MainOracleConnectionUIControl = 0x02200003, 28 | MainAccessConnectionUIControl = 0x02200004, 29 | MainOleDBConnectionUIControl = 0x02200005, 30 | MainOdbcConnectionUIControl = 0x02200006, 31 | MainGenericConnectionUIControl = 0x022FFFFF, 32 | MainAdvancedButton = 0x02400000, 33 | MainTestConnectionButton = 0x02800001, 34 | MainAcceptButton = 0x0280000E, 35 | MainCancelButton = 0x0280000F, 36 | 37 | Advanced = 0x04000000, 38 | AdvancedPropertyGrid = 0x04000001, 39 | AdvancedTextBox = 0x04000002, 40 | AdvancedOkButton = 0x04000003, 41 | AdvancedCancelButton = 0x04000004, 42 | 43 | AddProperty = 0x08000000, 44 | AddPropertyTextBox = 0x08000001, 45 | AddPropertyOkButton = 0x0800000E, 46 | AddPropertyCancelButton = 0x0800000F 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/DataConnectionSourceDialog.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Data.ConnectionUI 2 | { 3 | internal partial class DataConnectionSourceDialog 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | protected override void Dispose(bool disposing) 14 | { 15 | if (disposing && (components != null)) 16 | { 17 | components.Dispose(); 18 | } 19 | base.Dispose(disposing); 20 | } 21 | 22 | #region Windows Form Designer generated code 23 | 24 | /// 25 | /// Required method for Designer support - do not modify 26 | /// the contents of this method with the code editor. 27 | /// 28 | private void InitializeComponent() 29 | { 30 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DataConnectionSourceDialog)); 31 | this.mainTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 32 | this.leftPanel = new System.Windows.Forms.Panel(); 33 | this.dataSourceLabel = new System.Windows.Forms.Label(); 34 | this.dataSourceListBox = new System.Windows.Forms.ListBox(); 35 | this.dataProviderLabel = new System.Windows.Forms.Label(); 36 | this.dataProviderComboBox = new System.Windows.Forms.ComboBox(); 37 | this.descriptionGroupBox = new System.Windows.Forms.GroupBox(); 38 | this.descriptionLabel = new System.Windows.Forms.Label(); 39 | this.saveSelectionCheckBox = new System.Windows.Forms.CheckBox(); 40 | this.buttonsTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 41 | this.okButton = new System.Windows.Forms.Button(); 42 | this.cancelButton = new System.Windows.Forms.Button(); 43 | this.mainTableLayoutPanel.SuspendLayout(); 44 | this.leftPanel.SuspendLayout(); 45 | this.descriptionGroupBox.SuspendLayout(); 46 | this.buttonsTableLayoutPanel.SuspendLayout(); 47 | this.SuspendLayout(); 48 | // 49 | // mainTableLayoutPanel 50 | // 51 | resources.ApplyResources(this.mainTableLayoutPanel, "mainTableLayoutPanel"); 52 | this.mainTableLayoutPanel.Controls.Add(this.leftPanel, 0, 0); 53 | this.mainTableLayoutPanel.Controls.Add(this.descriptionGroupBox, 1, 0); 54 | this.mainTableLayoutPanel.Name = "mainTableLayoutPanel"; 55 | // 56 | // leftPanel 57 | // 58 | this.leftPanel.Controls.Add(this.dataSourceLabel); 59 | this.leftPanel.Controls.Add(this.dataSourceListBox); 60 | this.leftPanel.Controls.Add(this.dataProviderLabel); 61 | this.leftPanel.Controls.Add(this.dataProviderComboBox); 62 | resources.ApplyResources(this.leftPanel, "leftPanel"); 63 | this.leftPanel.Name = "leftPanel"; 64 | // 65 | // dataSourceLabel 66 | // 67 | resources.ApplyResources(this.dataSourceLabel, "dataSourceLabel"); 68 | this.dataSourceLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 69 | this.dataSourceLabel.Name = "dataSourceLabel"; 70 | // 71 | // dataSourceListBox 72 | // 73 | resources.ApplyResources(this.dataSourceListBox, "dataSourceListBox"); 74 | this.dataSourceListBox.FormattingEnabled = true; 75 | this.dataSourceListBox.MinimumSize = new System.Drawing.Size(200, 108); 76 | this.dataSourceListBox.Name = "dataSourceListBox"; 77 | this.dataSourceListBox.Sorted = true; 78 | this.dataSourceListBox.DoubleClick += new System.EventHandler(this.SelectDataSource); 79 | this.dataSourceListBox.SelectedIndexChanged += new System.EventHandler(this.ChangeDataSource); 80 | this.dataSourceListBox.Format += new System.Windows.Forms.ListControlConvertEventHandler(this.FormatDataSource); 81 | // 82 | // dataProviderLabel 83 | // 84 | resources.ApplyResources(this.dataProviderLabel, "dataProviderLabel"); 85 | this.dataProviderLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 86 | this.dataProviderLabel.Name = "dataProviderLabel"; 87 | // 88 | // dataProviderComboBox 89 | // 90 | resources.ApplyResources(this.dataProviderComboBox, "dataProviderComboBox"); 91 | this.dataProviderComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 92 | this.dataProviderComboBox.FormattingEnabled = true; 93 | this.dataProviderComboBox.Items.AddRange(new object[] { 94 | resources.GetString("dataProviderComboBox.Items")}); 95 | this.dataProviderComboBox.Name = "dataProviderComboBox"; 96 | this.dataProviderComboBox.Sorted = true; 97 | this.dataProviderComboBox.SelectedIndexChanged += new System.EventHandler(this.ChangeDataProvider); 98 | this.dataProviderComboBox.DropDown += new System.EventHandler(this.SetDataProviderDropDownWidth); 99 | this.dataProviderComboBox.Format += new System.Windows.Forms.ListControlConvertEventHandler(this.FormatDataProvider); 100 | // 101 | // descriptionGroupBox 102 | // 103 | resources.ApplyResources(this.descriptionGroupBox, "descriptionGroupBox"); 104 | this.descriptionGroupBox.Controls.Add(this.descriptionLabel); 105 | this.descriptionGroupBox.FlatStyle = System.Windows.Forms.FlatStyle.System; 106 | this.descriptionGroupBox.Name = "descriptionGroupBox"; 107 | this.descriptionGroupBox.TabStop = false; 108 | // 109 | // descriptionLabel 110 | // 111 | resources.ApplyResources(this.descriptionLabel, "descriptionLabel"); 112 | this.descriptionLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 113 | this.descriptionLabel.Name = "descriptionLabel"; 114 | // 115 | // saveSelectionCheckBox 116 | // 117 | resources.ApplyResources(this.saveSelectionCheckBox, "saveSelectionCheckBox"); 118 | this.saveSelectionCheckBox.Name = "saveSelectionCheckBox"; 119 | this.saveSelectionCheckBox.CheckedChanged += new System.EventHandler(this.SetSaveSelection); 120 | // 121 | // buttonsTableLayoutPanel 122 | // 123 | resources.ApplyResources(this.buttonsTableLayoutPanel, "buttonsTableLayoutPanel"); 124 | this.buttonsTableLayoutPanel.Controls.Add(this.okButton, 0, 0); 125 | this.buttonsTableLayoutPanel.Controls.Add(this.cancelButton, 1, 0); 126 | this.buttonsTableLayoutPanel.Name = "buttonsTableLayoutPanel"; 127 | // 128 | // okButton 129 | // 130 | resources.ApplyResources(this.okButton, "okButton"); 131 | this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; 132 | this.okButton.MinimumSize = new System.Drawing.Size(75, 23); 133 | this.okButton.Name = "okButton"; 134 | this.okButton.Click += new System.EventHandler(this.DoOk); 135 | // 136 | // cancelButton 137 | // 138 | resources.ApplyResources(this.cancelButton, "cancelButton"); 139 | this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; 140 | this.cancelButton.MinimumSize = new System.Drawing.Size(75, 23); 141 | this.cancelButton.Name = "cancelButton"; 142 | // 143 | // DataConnectionSourceDialog 144 | // 145 | this.AcceptButton = this.okButton; 146 | resources.ApplyResources(this, "$this"); 147 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 148 | this.CancelButton = this.cancelButton; 149 | this.Controls.Add(this.mainTableLayoutPanel); 150 | this.Controls.Add(this.saveSelectionCheckBox); 151 | this.Controls.Add(this.buttonsTableLayoutPanel); 152 | this.HelpButton = true; 153 | this.MaximizeBox = false; 154 | this.MinimizeBox = false; 155 | this.Name = "DataConnectionSourceDialog"; 156 | this.ShowIcon = false; 157 | this.ShowInTaskbar = false; 158 | this.mainTableLayoutPanel.ResumeLayout(false); 159 | this.leftPanel.ResumeLayout(false); 160 | this.leftPanel.PerformLayout(); 161 | this.descriptionGroupBox.ResumeLayout(false); 162 | this.buttonsTableLayoutPanel.ResumeLayout(false); 163 | this.buttonsTableLayoutPanel.PerformLayout(); 164 | this.ResumeLayout(false); 165 | this.PerformLayout(); 166 | 167 | } 168 | 169 | #endregion 170 | 171 | private System.Windows.Forms.TableLayoutPanel mainTableLayoutPanel; 172 | private System.Windows.Forms.Panel leftPanel; 173 | private System.Windows.Forms.Label dataSourceLabel; 174 | private System.Windows.Forms.ListBox dataSourceListBox; 175 | private System.Windows.Forms.Label dataProviderLabel; 176 | private System.Windows.Forms.ComboBox dataProviderComboBox; 177 | private System.Windows.Forms.GroupBox descriptionGroupBox; 178 | private System.Windows.Forms.Label descriptionLabel; 179 | private System.Windows.Forms.CheckBox saveSelectionCheckBox; 180 | private System.Windows.Forms.TableLayoutPanel buttonsTableLayoutPanel; 181 | private System.Windows.Forms.Button okButton; 182 | private System.Windows.Forms.Button cancelButton; 183 | } 184 | } 185 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/DataSource.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Diagnostics; 9 | using System.Collections.Generic; 10 | 11 | namespace Microsoft.Data.ConnectionUI 12 | { 13 | public class DataSource 14 | { 15 | public const string MicrosoftSqlServerFileName = "MicrosoftSqlServerFile"; 16 | 17 | private DataSource() 18 | { 19 | _displayName = Strings.DataSource_UnspecifiedDisplayName; 20 | _providers = new DataProviderCollection(this); 21 | } 22 | 23 | public DataSource(string name, string displayName) 24 | { 25 | if (name == null) 26 | { 27 | throw new ArgumentNullException("name"); 28 | } 29 | 30 | _name = name; 31 | _displayName = displayName; 32 | _providers = new DataProviderCollection(this); 33 | } 34 | 35 | public static void AddStandardDataSources(DataConnectionDialog dialog) 36 | { 37 | dialog.DataSources.Add(DataSource.SqlDataSource); 38 | dialog.DataSources.Add(DataSource.SqlFileDataSource); 39 | dialog.DataSources.Add(DataSource.OracleDataSource); 40 | dialog.DataSources.Add(DataSource.AccessDataSource); 41 | dialog.DataSources.Add(DataSource.OdbcDataSource); 42 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.SqlDataProvider); 43 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.OracleDataProvider); 44 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.OleDBDataProvider); 45 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.OdbcDataProvider); 46 | dialog.DataSources.Add(dialog.UnspecifiedDataSource); 47 | } 48 | 49 | public static DataSource SqlDataSource 50 | { 51 | get 52 | { 53 | if (_sqlDataSource == null) 54 | { 55 | _sqlDataSource = new DataSource("MicrosoftSqlServer", Strings.DataSource_MicrosoftSqlServer); 56 | _sqlDataSource.Providers.Add(DataProvider.SqlDataProvider); 57 | _sqlDataSource.Providers.Add(DataProvider.OleDBDataProvider); 58 | _sqlDataSource.DefaultProvider = DataProvider.SqlDataProvider; 59 | } 60 | return _sqlDataSource; 61 | } 62 | } 63 | private static DataSource _sqlDataSource; 64 | 65 | public static DataSource SqlFileDataSource 66 | { 67 | get 68 | { 69 | if (_sqlFileDataSource == null) 70 | { 71 | _sqlFileDataSource = new DataSource("MicrosoftSqlServerFile", Strings.DataSource_MicrosoftSqlServerFile); 72 | _sqlFileDataSource.Providers.Add(DataProvider.SqlDataProvider); 73 | } 74 | return _sqlFileDataSource; 75 | } 76 | } 77 | private static DataSource _sqlFileDataSource; 78 | 79 | public static DataSource OracleDataSource 80 | { 81 | get 82 | { 83 | if (_oracleDataSource == null) 84 | { 85 | _oracleDataSource = new DataSource("Oracle", Strings.DataSource_Oracle); 86 | _oracleDataSource.Providers.Add(DataProvider.OracleDataProvider); 87 | _oracleDataSource.Providers.Add(DataProvider.OleDBDataProvider); 88 | _oracleDataSource.DefaultProvider = DataProvider.OracleDataProvider; 89 | } 90 | return _oracleDataSource; 91 | } 92 | } 93 | private static DataSource _oracleDataSource; 94 | 95 | public static DataSource AccessDataSource 96 | { 97 | get 98 | { 99 | if (_accessDataSource == null) 100 | { 101 | _accessDataSource = new DataSource("MicrosoftAccess", Strings.DataSource_MicrosoftAccess); 102 | _accessDataSource.Providers.Add(DataProvider.OleDBDataProvider); 103 | } 104 | return _accessDataSource; 105 | } 106 | } 107 | private static DataSource _accessDataSource; 108 | 109 | public static DataSource OdbcDataSource 110 | { 111 | get 112 | { 113 | if (_odbcDataSource == null) 114 | { 115 | _odbcDataSource = new DataSource("OdbcDsn", Strings.DataSource_MicrosoftOdbcDsn); 116 | _odbcDataSource.Providers.Add(DataProvider.OdbcDataProvider); 117 | } 118 | return _odbcDataSource; 119 | } 120 | } 121 | private static DataSource _odbcDataSource; 122 | 123 | public string Name 124 | { 125 | get 126 | { 127 | return _name; 128 | } 129 | } 130 | 131 | public string DisplayName 132 | { 133 | get 134 | { 135 | return (_displayName != null) ? _displayName : _name; 136 | } 137 | } 138 | 139 | public DataProvider DefaultProvider 140 | { 141 | get 142 | { 143 | switch (_providers.Count) 144 | { 145 | case 0: 146 | Debug.Assert(_defaultProvider == null); 147 | return null; 148 | case 1: 149 | // If there is only one data provider, it must be the default 150 | IEnumerator e = _providers.GetEnumerator(); 151 | e.MoveNext(); 152 | return e.Current; 153 | default: 154 | return (_name != null) ? _defaultProvider : null; 155 | } 156 | } 157 | set 158 | { 159 | if (_providers.Count == 1 && _defaultProvider != value) 160 | { 161 | throw new InvalidOperationException(Strings.DataSource_CannotChangeSingleDataProvider); 162 | } 163 | if (value != null && !_providers.Contains(value)) 164 | { 165 | throw new InvalidOperationException(Strings.DataSource_DataProviderNotFound); 166 | } 167 | _defaultProvider = value; 168 | } 169 | } 170 | 171 | public ICollection Providers 172 | { 173 | get 174 | { 175 | return _providers; 176 | } 177 | } 178 | 179 | internal static DataSource CreateUnspecified() 180 | { 181 | return new DataSource(); 182 | } 183 | 184 | private class DataProviderCollection : ICollection 185 | { 186 | public DataProviderCollection(DataSource source) 187 | { 188 | Debug.Assert(source != null); 189 | 190 | _list = new List(); 191 | _source = source; 192 | } 193 | 194 | public int Count 195 | { 196 | get 197 | { 198 | return _list.Count; 199 | } 200 | } 201 | 202 | public bool IsReadOnly 203 | { 204 | get 205 | { 206 | return false; 207 | } 208 | } 209 | 210 | public void Add(DataProvider item) 211 | { 212 | if (item == null) 213 | { 214 | throw new ArgumentNullException("item"); 215 | } 216 | if (!_list.Contains(item)) 217 | { 218 | _list.Add(item); 219 | } 220 | } 221 | 222 | public bool Contains(DataProvider item) 223 | { 224 | return _list.Contains(item); 225 | } 226 | 227 | public bool Remove(DataProvider item) 228 | { 229 | bool result = _list.Remove(item); 230 | if (item == _source._defaultProvider) 231 | { 232 | _source._defaultProvider = null; 233 | } 234 | return result; 235 | } 236 | 237 | public void Clear() 238 | { 239 | _list.Clear(); 240 | _source._defaultProvider = null; 241 | } 242 | 243 | public void CopyTo(DataProvider[] array, int arrayIndex) 244 | { 245 | _list.CopyTo(array, arrayIndex); 246 | } 247 | 248 | public IEnumerator GetEnumerator() 249 | { 250 | return _list.GetEnumerator(); 251 | } 252 | 253 | System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() 254 | { 255 | return _list.GetEnumerator(); 256 | } 257 | 258 | private ICollection _list; 259 | private DataSource _source; 260 | } 261 | 262 | private string _name; 263 | private string _displayName; 264 | private DataProvider _defaultProvider; 265 | private ICollection _providers; 266 | } 267 | } 268 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/HelpUtils.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Diagnostics; 9 | using System.Windows.Forms; 10 | using System.Runtime.InteropServices; 11 | using System.Text; 12 | using System.Collections.Generic; 13 | 14 | namespace Microsoft.Data.ConnectionUI 15 | { 16 | internal sealed class HelpUtils 17 | { 18 | private const int KeyValueNameLength = 1024; // 1024 should be enough for registry key value name. 19 | 20 | private HelpUtils() 21 | { 22 | } 23 | 24 | public static bool IsContextHelpMessage(ref Message m) 25 | { 26 | return (m.Msg == NativeMethods.WM_SYSCOMMAND && ((int)m.WParam & 0xFFF0) == NativeMethods.SC_CONTEXTHELP); 27 | } 28 | 29 | /// 30 | /// This function checks if the OS is 64 bits. 31 | /// 32 | public static bool IsWow64() 33 | { 34 | bool isWow64 = false; 35 | if (Environment.OSVersion.Version.Major >= 5) 36 | { 37 | System.Diagnostics.Process curProcess = System.Diagnostics.Process.GetCurrentProcess(); 38 | try 39 | { 40 | NativeMethods.IsWow64Process(curProcess.Handle, out isWow64); 41 | } 42 | catch (Exception e) 43 | { 44 | isWow64 = false; 45 | Debug.Fail("Failed in calling IsWow64Process: " + e.Message); 46 | } 47 | } 48 | 49 | return isWow64; 50 | } 51 | 52 | /// 53 | /// Get ValueNames from registry for WoW64 machine. Corresponding to Microsoft.Win32.RegistryKey.GetValueNames(). 54 | /// 55 | /// Registry key string value 56 | /// Access key value options 57 | /// 58 | public static string[] GetValueNamesWow64(string registryKey, int ulOptions) 59 | { 60 | UIntPtr hKey = UIntPtr.Zero; 61 | UIntPtr nameKey = UIntPtr.Zero; 62 | int lResult = 0; 63 | string[] valueNames = null; 64 | 65 | try 66 | { 67 | lResult = NativeMethods.RegOpenKeyEx(NativeMethods.HKEY_LOCAL_MACHINE, registryKey, 0, ulOptions, out nameKey); 68 | } 69 | catch 70 | { 71 | // Ignore native exceptions. 72 | } 73 | if (lResult == 0 && UIntPtr.Equals(nameKey, UIntPtr.Zero) == false) 74 | { 75 | uint numSubKeys, numValues = 0; 76 | try 77 | { 78 | lResult = NativeMethods.RegQueryInfoKey(nameKey, null, IntPtr.Zero, IntPtr.Zero, out numSubKeys, IntPtr.Zero, IntPtr.Zero, out numValues, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); 79 | } 80 | catch 81 | { 82 | // Ignore native exceptions. 83 | } 84 | 85 | if (lResult == 0) 86 | { 87 | valueNames = new string[numValues]; 88 | 89 | for (uint index = 0; index < numValues; index++) 90 | { 91 | StringBuilder builder = new StringBuilder(KeyValueNameLength); 92 | uint size = KeyValueNameLength; 93 | 94 | try 95 | { 96 | lResult = NativeMethods.RegEnumValue(nameKey, index, builder, ref size, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); 97 | } 98 | catch 99 | { 100 | // Ignore native exceptions. 101 | } 102 | 103 | if (lResult == 0) 104 | { 105 | valueNames[index] = builder.ToString(); 106 | } 107 | } 108 | } 109 | } 110 | if (valueNames != null) 111 | { 112 | return valueNames; 113 | } 114 | else 115 | { 116 | return new string[0]; 117 | } 118 | } 119 | 120 | public static void TranslateContextHelpMessage(Form f, ref Message m) 121 | { 122 | Debug.Assert(f != null); 123 | 124 | Control activeControl = GetActiveControl(f); 125 | if (activeControl != null) 126 | { 127 | // Turn this message into a WM_HELP message 128 | m.HWnd = activeControl.Handle; 129 | m.Msg = NativeMethods.WM_HELP; 130 | m.WParam = IntPtr.Zero; 131 | NativeMethods.HELPINFO helpInfo = new NativeMethods.HELPINFO(); 132 | helpInfo.iContextType = NativeMethods.HELPINFO_WINDOW; 133 | helpInfo.iCtrlId = f.Handle.ToInt32(); 134 | helpInfo.hItemHandle = activeControl.Handle; 135 | helpInfo.dwContextId = 0; 136 | helpInfo.MousePos.x = (int)NativeMethods.LOWORD((int)m.LParam); 137 | helpInfo.MousePos.y = (int)NativeMethods.HIWORD((int)m.LParam); 138 | m.LParam = Marshal.AllocHGlobal(Marshal.SizeOf(helpInfo)); 139 | Marshal.StructureToPtr(helpInfo, m.LParam, false); 140 | } 141 | } 142 | 143 | public static Control GetActiveControl(Form f) 144 | { 145 | Control activeControl = f; 146 | ContainerControl containerControl = null; 147 | while ((containerControl = activeControl as ContainerControl) != null && 148 | containerControl.ActiveControl != null) 149 | { 150 | activeControl = containerControl.ActiveControl; 151 | } 152 | return activeControl; 153 | } 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/LayoutUtils.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | using System; 7 | using System.Drawing; 8 | using System.Windows.Forms; 9 | 10 | namespace Microsoft.Data.ConnectionUI 11 | { 12 | internal sealed class LayoutUtils 13 | { 14 | private LayoutUtils() 15 | { 16 | } 17 | 18 | public static int GetPreferredLabelHeight(Label label) 19 | { 20 | return GetPreferredLabelHeight(label, label.Width); 21 | } 22 | 23 | public static int GetPreferredLabelHeight(Label label, int requiredWidth) 24 | { 25 | return GetPreferredHeight(label, label.UseCompatibleTextRendering, requiredWidth); 26 | } 27 | 28 | public static int GetPreferredCheckBoxHeight(CheckBox checkBox) 29 | { 30 | return GetPreferredHeight(checkBox, checkBox.UseCompatibleTextRendering, checkBox.Width); 31 | } 32 | 33 | public static void MirrorControl(Control c) 34 | { 35 | c.Left = 36 | c.Parent.Right - 37 | c.Parent.Padding.Left - 38 | c.Margin.Left - 39 | c.Width; 40 | if ((c.Anchor & AnchorStyles.Left) == 0 || 41 | (c.Anchor & AnchorStyles.Right) == 0) 42 | { 43 | c.Anchor &= ~AnchorStyles.Left; 44 | c.Anchor |= AnchorStyles.Right; 45 | } 46 | } 47 | 48 | public static void MirrorControl(Control c, Control pivot) 49 | { 50 | c.Left = pivot.Right - c.Width; 51 | if ((c.Anchor & AnchorStyles.Left) == 0 || 52 | (c.Anchor & AnchorStyles.Right) == 0) 53 | { 54 | c.Anchor &= ~AnchorStyles.Left; 55 | c.Anchor |= AnchorStyles.Right; 56 | } 57 | } 58 | 59 | public static void UnmirrorControl(Control c) 60 | { 61 | c.Left = 62 | c.Parent.Left + 63 | c.Parent.Padding.Left + 64 | c.Margin.Left; 65 | if ((c.Anchor & AnchorStyles.Left) == 0 || 66 | (c.Anchor & AnchorStyles.Right) == 0) 67 | { 68 | c.Anchor &= ~AnchorStyles.Right; 69 | c.Anchor |= AnchorStyles.Left; 70 | } 71 | } 72 | 73 | public static void UnmirrorControl(Control c, Control pivot) 74 | { 75 | c.Left = pivot.Left; 76 | if ((c.Anchor & AnchorStyles.Left) == 0 || 77 | (c.Anchor & AnchorStyles.Right) == 0) 78 | { 79 | c.Anchor &= ~AnchorStyles.Right; 80 | c.Anchor |= AnchorStyles.Left; 81 | } 82 | } 83 | 84 | private static int GetPreferredHeight(Control c, bool useCompatibleTextRendering, int requiredWidth) 85 | { 86 | using (Graphics g = Graphics.FromHwnd(c.Handle)) 87 | { 88 | if (useCompatibleTextRendering) 89 | { 90 | return g.MeasureString(c.Text, c.Font, c.Width).ToSize().Height; 91 | } 92 | else 93 | { 94 | return TextRenderer.MeasureText( 95 | g, 96 | c.Text, 97 | c.Font, 98 | new Size(requiredWidth, Int32.MaxValue), 99 | TextFormatFlags.WordBreak 100 | ).Height; 101 | } 102 | } 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/Microsoft.Data.ConnectionUI.Dialog.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | true 7 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA} 8 | Microsoft.Data.ConnectionUI.Dialog 9 | Library 10 | bin\Debug\ 11 | true 12 | 13 | 14 | v3.5 15 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA} 16 | Microsoft.Data.ConnectionUI 17 | 18 | 19 | 20 | 21 | 3.5 22 | 23 | 24 | true 25 | bin\x86\Debug\ 26 | x86 27 | true 28 | GlobalSuppressions.cs 29 | 30 | 31 | true 32 | bin\x64\Debug\ 33 | x64 34 | true 35 | GlobalSuppressions.cs 36 | 37 | 38 | 39 | 40 | UserControl 41 | 42 | 43 | AccessConnectionUIControl.cs 44 | 45 | 46 | Form 47 | 48 | 49 | AddPropertyDialog.cs 50 | 51 | 52 | 53 | 54 | Form 55 | 56 | 57 | DataConnectionAdvancedDialog.cs 58 | 59 | 60 | Form 61 | 62 | 63 | DataConnectionDialog.cs 64 | 65 | 66 | 67 | Form 68 | 69 | 70 | DataConnectionSourceDialog.cs 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | UserControl 81 | 82 | 83 | OdbcConnectionUIControl.cs 84 | 85 | 86 | 87 | UserControl 88 | 89 | 90 | OleDBConnectionUIControl.cs 91 | 92 | 93 | 94 | UserControl 95 | 96 | 97 | OracleConnectionUIControl.cs 98 | 99 | 100 | 101 | 102 | UserControl 103 | 104 | 105 | SqlConnectionUIControl.cs 106 | 107 | 108 | UserControl 109 | 110 | 111 | SqlExpressConnectionUIControl.cs 112 | 113 | 114 | True 115 | True 116 | Strings.resx 117 | 118 | 119 | 120 | 121 | 122 | AccessConnectionUIControl.cs 123 | 124 | 125 | AddPropertyDialog.cs 126 | 127 | 128 | DataConnectionAdvancedDialog.cs 129 | 130 | 131 | DataConnectionDialog.cs 132 | 133 | 134 | DataConnectionSourceDialog.cs 135 | 136 | 137 | OdbcConnectionUIControl.cs 138 | 139 | 140 | OleDBConnectionUIControl.cs 141 | 142 | 143 | OracleConnectionUIControl.cs 144 | 145 | 146 | SqlConnectionUIControl.cs 147 | 148 | 149 | SqlExpressConnectionUIControl.cs 150 | 151 | 152 | ResXFileCodeGenerator 153 | Strings.Designer.cs 154 | Designer 155 | 156 | 157 | 158 | 159 | 160 | 161 | 3.5 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 3.5 175 | 176 | 177 | 178 | 179 | {4E92A2A2-FE80-4021-A434-BF37A63CD69D} 180 | Microsoft.Data.ConnectionUI 181 | Needs 'microsoft.data.connectionui.dll' 182 | 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Runtime.InteropServices; 9 | using System.Text; 10 | 11 | // FxCop enforces that we add this attribute 12 | [assembly: System.Runtime.ConstrainedExecution.ReliabilityContract(System.Runtime.ConstrainedExecution.Consistency.MayCorruptProcess, System.Runtime.ConstrainedExecution.Cer.None)] 13 | 14 | namespace Microsoft.Data.ConnectionUI 15 | { 16 | internal sealed class NativeMethods 17 | { 18 | private NativeMethods() 19 | { 20 | } 21 | 22 | #region Macros 23 | 24 | internal static bool SQL_SUCCEEDED(short rc) 25 | { 26 | return (((rc) & (~1)) == 0); 27 | } 28 | 29 | internal static short LOWORD(int dwValue) 30 | { 31 | return (short)(dwValue & 0xffff); 32 | } 33 | 34 | internal static short HIWORD(int dwValue) 35 | { 36 | return (short)((dwValue >> 16) & 0xffff); 37 | } 38 | 39 | #endregion 40 | 41 | #region Interfaces 42 | 43 | [ComImport] 44 | [Guid("2206CCB1-19C1-11D1-89E0-00C04FD7A829")] 45 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 46 | internal interface IDataInitialize 47 | { 48 | void GetDataSource( 49 | [In, MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter, 50 | [In, MarshalAs(UnmanagedType.U4)] int dwClsCtx, 51 | [In, MarshalAs(UnmanagedType.LPWStr)] string pwszInitializationString, 52 | [In] ref Guid riid, 53 | [In, Out, MarshalAs(UnmanagedType.IUnknown)] ref object ppDataSource); 54 | 55 | void GetInitializationString( 56 | [In, MarshalAs(UnmanagedType.IUnknown)] object pDataSource, 57 | [In, MarshalAs(UnmanagedType.I1)] bool fIncludePassword, 58 | [Out, MarshalAs(UnmanagedType.LPWStr)] out string ppwszInitString); 59 | 60 | void Unused_CreateDBInstance(); 61 | void Unused_CreateDBInstanceEx(); 62 | void Unused_LoadStringFromStorage(); 63 | void Unused_WriteStringToStorage(); 64 | } 65 | 66 | [ComImport] 67 | [Guid("2206CCB0-19C1-11D1-89E0-00C04FD7A829")] 68 | [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] 69 | internal interface IDBPromptInitialize 70 | { 71 | void PromptDataSource( 72 | [In, MarshalAs(UnmanagedType.IUnknown)] object pUnkOuter, 73 | [In] IntPtr hwndParent, 74 | [In, MarshalAs(UnmanagedType.U4)] int dwPromptOptions, 75 | [In, MarshalAs(UnmanagedType.U4)] int cSourceTypeFilter, 76 | [In] IntPtr rgSourceTypeFilter, 77 | [In, MarshalAs(UnmanagedType.LPWStr)] string pwszszzProviderFilter, 78 | [In] ref Guid riid, 79 | [In, Out, MarshalAs(UnmanagedType.IUnknown)] ref object ppDataSource); 80 | 81 | void Unused_PromptFileName(); 82 | } 83 | 84 | #endregion 85 | 86 | #region Structures 87 | 88 | [StructLayout(LayoutKind.Sequential)] 89 | internal class HELPINFO 90 | { 91 | public int cbSize = Marshal.SizeOf(typeof(HELPINFO)); 92 | public int iContextType; 93 | public int iCtrlId; 94 | public IntPtr hItemHandle; 95 | public int dwContextId; 96 | public POINT MousePos; 97 | } 98 | 99 | [StructLayout(LayoutKind.Sequential)] 100 | internal struct POINT 101 | { 102 | public int x; 103 | public int y; 104 | } 105 | 106 | #endregion 107 | 108 | #region Functions 109 | 110 | [DllImport("odbc32.dll")] 111 | internal static extern short SQLAllocEnv(out IntPtr EnvironmentHandle); 112 | 113 | [DllImport("odbc32.dll")] 114 | internal static extern short SQLAllocConnect(IntPtr EnvironmentHandle, out IntPtr ConnectionHandle); 115 | 116 | [DllImport("odbc32.dll", EntryPoint = "SQLDriverConnectW", CharSet = CharSet.Unicode)] 117 | internal static extern short SQLDriverConnect(IntPtr hdbc, IntPtr hwnd, string szConnStrIn, short cbConnStrIn, System.Text.StringBuilder szConnStrOut, short cbConnStrOutMax, out short pcbConnStrOut, ushort fDriverCompletion); 118 | 119 | [DllImport("odbc32.dll")] 120 | internal static extern short SQLDisconnect(IntPtr ConnectionHandle); 121 | 122 | [DllImport("odbc32.dll")] 123 | internal static extern short SQLFreeConnect(IntPtr ConnectionHandle); 124 | 125 | [DllImport("odbc32.dll")] 126 | internal static extern short SQLFreeEnv(IntPtr EnvironmentHandle); 127 | 128 | [DllImport("odbccp32.dll", CharSet = CharSet.Unicode)] 129 | internal static extern bool SQLGetInstalledDrivers(char[] lpszBuf, int cbBufMax, ref int pcbBufOut); 130 | 131 | [DllImport("odbccp32.dll", CharSet = CharSet.Unicode)] 132 | internal static extern int SQLGetPrivateProfileString(string lpszSection, string lpszEntry, string lpszDefault, StringBuilder RetBuffer, int cbRetBuffer, string lpszFilename); 133 | 134 | // Used to check if OS is 64 bits 135 | [DllImport("kernel32")] 136 | [return: MarshalAs(UnmanagedType.Bool)] 137 | internal static extern bool IsWow64Process(IntPtr hProcess, out bool pIsWow64); 138 | 139 | // Used to access 64 bit registry section from 32 bits application 140 | [DllImport("advapi32")] 141 | internal static extern int RegOpenKeyEx(UIntPtr hKey, string lpSubKey, int ulOptions, int samDesired, out UIntPtr phkResult); 142 | [DllImport("advapi32")] 143 | internal static extern int RegQueryValueEx(UIntPtr hKey, string lpValueName, uint lpReserved, ref uint lpType, IntPtr lpData, ref int lpchData); 144 | [DllImport("advapi32.dll")] 145 | internal static extern int RegQueryInfoKey(UIntPtr hkey, byte[] lpClass, IntPtr lpcbClass, IntPtr lpReserved, out uint lpcSubKeys, IntPtr lpcbMaxSubKeyLen, IntPtr lpcbMaxClassLen, out uint lpcValues, IntPtr lpcbMaxValueNameLen, IntPtr lpcbMaxValueLen, IntPtr lpcbSecurityDescriptor, IntPtr lpftLastWriteTime); 146 | [DllImport("advapi32.dll")] 147 | internal static extern int RegEnumValue(UIntPtr hkey, uint index, StringBuilder lpValueName, ref uint lpcbValueName, IntPtr reserved, IntPtr lpType, IntPtr lpData, IntPtr lpcbData); 148 | [DllImport("advapi32")] 149 | internal static extern uint RegCloseKey(UIntPtr hKey); 150 | 151 | internal static readonly UIntPtr HKEY_LOCAL_MACHINE = new UIntPtr(((uint)0x80000002)); 152 | internal const int KEY_WOW64_64KEY = 0x0100; 153 | internal const int KEY_WOW64_32KEY = 0x0200; 154 | internal const int KEY_QUERY_VALUE = 0x1; 155 | 156 | #endregion 157 | 158 | #region Guids 159 | 160 | internal static Guid IID_IUnknown = new Guid("00000000-0000-0000-c000-000000000046"); 161 | internal static Guid CLSID_DataLinks = new Guid("2206CDB2-19C1-11d1-89E0-00C04FD7A829"); 162 | internal static Guid CLSID_OLEDB_ENUMERATOR = new Guid("C8B522D0-5CF3-11ce-ADE5-00AA0044773D"); 163 | internal static Guid CLSID_MSDASQL_ENUMERATOR = new Guid("C8B522CD-5CF3-11ce-ADE5-00AA0044773D"); 164 | 165 | #endregion 166 | 167 | #region Constants 168 | 169 | // HRESULT codes 170 | internal const int 171 | DB_E_CANCELED = unchecked((int)0x80040E4E); 172 | 173 | // COM class contexts 174 | internal const int 175 | CLSCTX_INPROC_SERVER = 1; 176 | 177 | // Window messages 178 | internal const int 179 | WM_SETFOCUS = 0x0007, 180 | WM_HELP = 0x0053, 181 | WM_CONTEXTMENU = 0x007B, 182 | WM_SYSCOMMAND = 0x0112; 183 | 184 | // Window system commands 185 | internal const int 186 | SC_CONTEXTHELP = 0xF180; 187 | 188 | // HELPINFO constants 189 | internal const int 190 | HELPINFO_WINDOW = 0x0001; 191 | 192 | // OLE DB database source types 193 | internal const int 194 | DBSOURCETYPE_DATASOURCE_TDP = 1, 195 | DBSOURCETYPE_DATASOURCE_MDP = 3; 196 | 197 | // OLE DB Data Links dialog prompt options 198 | internal const int 199 | DBPROMPTOPTIONS_PROPERTYSHEET = 0x02, 200 | DBPROMPTOPTIONS_DISABLE_PROVIDER_SELECTION = 0x10; 201 | 202 | // ODBC Driver prompt options 203 | internal const ushort 204 | SQL_DRIVER_PROMPT = 2; 205 | 206 | // ODBC return values 207 | internal const short 208 | SQL_NO_DATA = 100; 209 | 210 | #endregion 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/OdbcConnectionProperties.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Diagnostics; 9 | using System.ComponentModel; 10 | using System.Collections.Generic; 11 | using System.Text; 12 | 13 | namespace Microsoft.Data.ConnectionUI 14 | { 15 | public class OdbcConnectionProperties : AdoDotNetConnectionProperties 16 | { 17 | private static List _sqlNativeClientDrivers = null; 18 | 19 | public OdbcConnectionProperties() 20 | : base("System.Data.Odbc") 21 | { 22 | } 23 | 24 | public override bool IsComplete 25 | { 26 | get 27 | { 28 | if ((!(ConnectionStringBuilder["DSN"] is string) || 29 | (ConnectionStringBuilder["DSN"] as string).Length == 0) && 30 | (!(ConnectionStringBuilder["DRIVER"] is string) || 31 | (ConnectionStringBuilder["DRIVER"] as string).Length == 0)) 32 | { 33 | return false; 34 | } 35 | return true; 36 | } 37 | } 38 | 39 | public static List SqlNativeClientDrivers 40 | { 41 | get 42 | { 43 | if (_sqlNativeClientDrivers == null) 44 | { 45 | _sqlNativeClientDrivers = new List(); 46 | 47 | List driverDescList = ManagedSQLGetInstalledDrivers(); 48 | Debug.Assert(driverDescList != null, "driver list is null"); 49 | foreach (string driverDesc in driverDescList) 50 | { 51 | if (driverDesc.Contains("Native") && driverDesc.Contains("Client")) 52 | { 53 | StringBuilder driverBuf = new StringBuilder(1024); 54 | int len = NativeMethods.SQLGetPrivateProfileString(driverDesc, "Driver", "", driverBuf, driverBuf.Capacity, "ODBCINST.INI"); 55 | if (len > 0 && driverBuf.Length > 0) 56 | { 57 | string driver = driverBuf.ToString(); 58 | int start = driver.LastIndexOf('\\'); 59 | if (start > 0) 60 | { 61 | _sqlNativeClientDrivers.Add(driver.Substring(start + 1).ToUpperInvariant()); 62 | } 63 | } 64 | } 65 | } 66 | 67 | _sqlNativeClientDrivers.Sort(); 68 | } 69 | 70 | Debug.Assert(_sqlNativeClientDrivers != null, "Native Client list is null"); 71 | return _sqlNativeClientDrivers; 72 | } 73 | } 74 | 75 | private static List ManagedSQLGetInstalledDrivers() 76 | { 77 | char[] lpszBuf = new char[1024]; 78 | int pcbBufOut = 0; 79 | bool succeed = true; 80 | List driverList = new List(); 81 | 82 | try 83 | { 84 | succeed = NativeMethods.SQLGetInstalledDrivers(lpszBuf, lpszBuf.Length, ref pcbBufOut); 85 | 86 | while (succeed && pcbBufOut > 0 && 87 | pcbBufOut == (lpszBuf.Length - 1) && 88 | lpszBuf.Length < Math.Pow(2, 30) /* sanity limit */ ) 89 | { 90 | // The managed buffer needs to be bigger 91 | lpszBuf = new char[lpszBuf.Length * 2]; 92 | 93 | succeed = NativeMethods.SQLGetInstalledDrivers(lpszBuf, lpszBuf.Length, ref pcbBufOut); 94 | } 95 | } 96 | catch (Exception e) 97 | { 98 | Debug.Fail(e.ToString()); 99 | succeed = false; 100 | } 101 | 102 | if (succeed) 103 | { 104 | for (int start = 0, end = Array.IndexOf(lpszBuf, '\0', start, (pcbBufOut - 1)); 105 | start < (pcbBufOut - 1); 106 | start = end + 1, end = Array.IndexOf(lpszBuf, '\0', start, (pcbBufOut - 1) - end)) 107 | { 108 | driverList.Add(new string(lpszBuf, start, end - start)); 109 | } 110 | } 111 | 112 | return driverList; 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/OracleConnectionProperties.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | 9 | namespace Microsoft.Data.ConnectionUI 10 | { 11 | public class OracleConnectionProperties : AdoDotNetConnectionProperties 12 | { 13 | public OracleConnectionProperties() 14 | : base("System.Data.OracleClient") 15 | { 16 | LocalReset(); 17 | } 18 | 19 | public override void Reset() 20 | { 21 | base.Reset(); 22 | LocalReset(); 23 | } 24 | 25 | public override bool IsComplete 26 | { 27 | get 28 | { 29 | if (!(ConnectionStringBuilder["Data Source"] is string) || 30 | (ConnectionStringBuilder["Data Source"] as string).Length == 0) 31 | { 32 | return false; 33 | } 34 | if (!(bool)ConnectionStringBuilder["Integrated Security"] && 35 | (!(ConnectionStringBuilder["User ID"] is string) || 36 | (ConnectionStringBuilder["User ID"] as string).Length == 0)) 37 | { 38 | return false; 39 | } 40 | return true; 41 | } 42 | } 43 | 44 | protected override string ToTestString() 45 | { 46 | bool savedPooling = (bool)ConnectionStringBuilder["Pooling"]; 47 | bool wasDefault = !ConnectionStringBuilder.ShouldSerialize("Pooling"); 48 | ConnectionStringBuilder["Pooling"] = false; 49 | string testString = ConnectionStringBuilder.ConnectionString; 50 | ConnectionStringBuilder["Pooling"] = savedPooling; 51 | if (wasDefault) 52 | { 53 | ConnectionStringBuilder.Remove("Pooling"); 54 | } 55 | return testString; 56 | } 57 | 58 | private void LocalReset() 59 | { 60 | // We always start with unicode turned on 61 | this["Unicode"] = true; 62 | } 63 | 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/OracleConnectionUIControl.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Data.ConnectionUI 2 | { 3 | public partial class OracleConnectionUIControl 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | protected override void Dispose(bool disposing) 14 | { 15 | if (disposing && (components != null)) 16 | { 17 | components.Dispose(); 18 | } 19 | base.Dispose(disposing); 20 | } 21 | 22 | #region Component Designer generated code 23 | 24 | /// 25 | /// Required method for Designer support - do not modify 26 | /// the contents of this method with the code editor. 27 | /// 28 | private void InitializeComponent() 29 | { 30 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(OracleConnectionUIControl)); 31 | this.serverLabel = new System.Windows.Forms.Label(); 32 | this.serverTextBox = new System.Windows.Forms.TextBox(); 33 | this.logonGroupBox = new System.Windows.Forms.GroupBox(); 34 | this.loginTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 35 | this.userNameLabel = new System.Windows.Forms.Label(); 36 | this.userNameTextBox = new System.Windows.Forms.TextBox(); 37 | this.passwordLabel = new System.Windows.Forms.Label(); 38 | this.passwordTextBox = new System.Windows.Forms.TextBox(); 39 | this.savePasswordCheckBox = new System.Windows.Forms.CheckBox(); 40 | this.logonGroupBox.SuspendLayout(); 41 | this.loginTableLayoutPanel.SuspendLayout(); 42 | this.SuspendLayout(); 43 | // 44 | // serverLabel 45 | // 46 | resources.ApplyResources(this.serverLabel, "serverLabel"); 47 | this.serverLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 48 | this.serverLabel.Name = "serverLabel"; 49 | // 50 | // serverTextBox 51 | // 52 | resources.ApplyResources(this.serverTextBox, "serverTextBox"); 53 | this.serverTextBox.Name = "serverTextBox"; 54 | this.serverTextBox.Leave += new System.EventHandler(this.TrimControlText); 55 | this.serverTextBox.TextChanged += new System.EventHandler(this.SetServer); 56 | // 57 | // logonGroupBox 58 | // 59 | resources.ApplyResources(this.logonGroupBox, "logonGroupBox"); 60 | this.logonGroupBox.Controls.Add(this.loginTableLayoutPanel); 61 | this.logonGroupBox.FlatStyle = System.Windows.Forms.FlatStyle.System; 62 | this.logonGroupBox.Name = "logonGroupBox"; 63 | this.logonGroupBox.TabStop = false; 64 | // 65 | // loginTableLayoutPanel 66 | // 67 | resources.ApplyResources(this.loginTableLayoutPanel, "loginTableLayoutPanel"); 68 | this.loginTableLayoutPanel.Controls.Add(this.userNameLabel, 0, 0); 69 | this.loginTableLayoutPanel.Controls.Add(this.userNameTextBox, 1, 0); 70 | this.loginTableLayoutPanel.Controls.Add(this.passwordLabel, 0, 1); 71 | this.loginTableLayoutPanel.Controls.Add(this.passwordTextBox, 1, 1); 72 | this.loginTableLayoutPanel.Controls.Add(this.savePasswordCheckBox, 1, 2); 73 | this.loginTableLayoutPanel.Name = "loginTableLayoutPanel"; 74 | // 75 | // userNameLabel 76 | // 77 | resources.ApplyResources(this.userNameLabel, "userNameLabel"); 78 | this.userNameLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 79 | this.userNameLabel.Name = "userNameLabel"; 80 | // 81 | // userNameTextBox 82 | // 83 | resources.ApplyResources(this.userNameTextBox, "userNameTextBox"); 84 | this.userNameTextBox.Name = "userNameTextBox"; 85 | this.userNameTextBox.Leave += new System.EventHandler(this.TrimControlText); 86 | this.userNameTextBox.TextChanged += new System.EventHandler(this.SetUserName); 87 | // 88 | // passwordLabel 89 | // 90 | resources.ApplyResources(this.passwordLabel, "passwordLabel"); 91 | this.passwordLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 92 | this.passwordLabel.Name = "passwordLabel"; 93 | // 94 | // passwordTextBox 95 | // 96 | resources.ApplyResources(this.passwordTextBox, "passwordTextBox"); 97 | this.passwordTextBox.Name = "passwordTextBox"; 98 | this.passwordTextBox.UseSystemPasswordChar = true; 99 | this.passwordTextBox.TextChanged += new System.EventHandler(this.SetPassword); 100 | // 101 | // savePasswordCheckBox 102 | // 103 | resources.ApplyResources(this.savePasswordCheckBox, "savePasswordCheckBox"); 104 | this.savePasswordCheckBox.Name = "savePasswordCheckBox"; 105 | this.savePasswordCheckBox.CheckedChanged += new System.EventHandler(this.SetSavePassword); 106 | // 107 | // OracleConnectionUIControl 108 | // 109 | resources.ApplyResources(this, "$this"); 110 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 111 | this.Controls.Add(this.logonGroupBox); 112 | this.Controls.Add(this.serverTextBox); 113 | this.Controls.Add(this.serverLabel); 114 | this.MinimumSize = new System.Drawing.Size(300, 146); 115 | this.Name = "OracleConnectionUIControl"; 116 | this.logonGroupBox.ResumeLayout(false); 117 | this.logonGroupBox.PerformLayout(); 118 | this.loginTableLayoutPanel.ResumeLayout(false); 119 | this.loginTableLayoutPanel.PerformLayout(); 120 | this.ResumeLayout(false); 121 | this.PerformLayout(); 122 | 123 | } 124 | 125 | #endregion 126 | 127 | private System.Windows.Forms.Label serverLabel; 128 | private System.Windows.Forms.TextBox serverTextBox; 129 | private System.Windows.Forms.GroupBox logonGroupBox; 130 | private System.Windows.Forms.TableLayoutPanel loginTableLayoutPanel; 131 | private System.Windows.Forms.Label userNameLabel; 132 | private System.Windows.Forms.TextBox userNameTextBox; 133 | private System.Windows.Forms.Label passwordLabel; 134 | private System.Windows.Forms.TextBox passwordTextBox; 135 | private System.Windows.Forms.CheckBox savePasswordCheckBox; 136 | 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/OracleConnectionUIControl.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Drawing; 9 | using System.Diagnostics; 10 | using System.Windows.Forms; 11 | 12 | namespace Microsoft.Data.ConnectionUI 13 | { 14 | public partial class OracleConnectionUIControl : UserControl, IDataConnectionUIControl 15 | { 16 | public OracleConnectionUIControl() 17 | { 18 | InitializeComponent(); 19 | RightToLeft = RightToLeft.Inherit; 20 | 21 | int requiredHeight = LayoutUtils.GetPreferredCheckBoxHeight(savePasswordCheckBox); 22 | if (savePasswordCheckBox.Height < requiredHeight) 23 | { 24 | savePasswordCheckBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom; 25 | loginTableLayoutPanel.Height += loginTableLayoutPanel.Margin.Bottom; 26 | loginTableLayoutPanel.Margin = new Padding(loginTableLayoutPanel.Margin.Left, loginTableLayoutPanel.Margin.Top, loginTableLayoutPanel.Margin.Right, 0); 27 | } 28 | } 29 | 30 | public void Initialize(IDataConnectionProperties connectionProperties) 31 | { 32 | if (connectionProperties == null) 33 | { 34 | throw new ArgumentNullException("connectionProperties"); 35 | } 36 | 37 | if (!(connectionProperties is OracleConnectionProperties) && 38 | !(connectionProperties is OleDBOracleConnectionProperties)) 39 | { 40 | throw new ArgumentException(Strings.OracleConnectionUIControl_InvalidConnectionProperties); 41 | } 42 | 43 | if (connectionProperties is OdbcConnectionProperties) 44 | { 45 | // ODBC does not support saving the password 46 | savePasswordCheckBox.Enabled = false; 47 | } 48 | 49 | _connectionProperties = connectionProperties; 50 | } 51 | 52 | public void LoadProperties() 53 | { 54 | _loading = true; 55 | 56 | serverTextBox.Text = Properties[ServerProperty] as string; 57 | userNameTextBox.Text = Properties[UserNameProperty] as string; 58 | passwordTextBox.Text = Properties[PasswordProperty] as string; 59 | if (!(Properties is OdbcConnectionProperties)) 60 | { 61 | savePasswordCheckBox.Checked = (bool)Properties["Persist Security Info"]; 62 | } 63 | else 64 | { 65 | savePasswordCheckBox.Checked = false; 66 | } 67 | 68 | _loading = false; 69 | } 70 | 71 | // Simulate RTL mirroring 72 | protected override void OnRightToLeftChanged(EventArgs e) 73 | { 74 | base.OnRightToLeftChanged(e); 75 | if (ParentForm != null && 76 | ParentForm.RightToLeftLayout == true && 77 | RightToLeft == RightToLeft.Yes) 78 | { 79 | LayoutUtils.MirrorControl(serverLabel, serverTextBox); 80 | } 81 | else 82 | { 83 | LayoutUtils.UnmirrorControl(serverLabel, serverTextBox); 84 | } 85 | } 86 | 87 | protected override void ScaleControl(SizeF factor, BoundsSpecified specified) 88 | { 89 | Size baseSize = Size; 90 | MinimumSize = Size.Empty; 91 | base.ScaleControl(factor, specified); 92 | MinimumSize = new Size( 93 | (int)Math.Round((float)baseSize.Width * factor.Width), 94 | (int)Math.Round((float)baseSize.Height * factor.Height)); 95 | } 96 | 97 | protected override void OnParentChanged(EventArgs e) 98 | { 99 | base.OnParentChanged(e); 100 | if (Parent == null) 101 | { 102 | OnFontChanged(e); 103 | } 104 | } 105 | 106 | private void SetServer(object sender, System.EventArgs e) 107 | { 108 | if (!_loading) 109 | { 110 | Properties[ServerProperty] = (serverTextBox.Text.Trim().Length > 0) ? serverTextBox.Text.Trim() : null; 111 | } 112 | } 113 | 114 | private void SetUserName(object sender, EventArgs e) 115 | { 116 | if (!_loading) 117 | { 118 | Properties[UserNameProperty] = (userNameTextBox.Text.Trim().Length > 0) ? userNameTextBox.Text.Trim() : null; 119 | } 120 | } 121 | 122 | private void SetPassword(object sender, EventArgs e) 123 | { 124 | if (!_loading) 125 | { 126 | Properties[PasswordProperty] = (passwordTextBox.Text.Length > 0) ? passwordTextBox.Text : null; 127 | passwordTextBox.Text = passwordTextBox.Text; // forces reselection of all text 128 | } 129 | } 130 | 131 | private void SetSavePassword(object sender, EventArgs e) 132 | { 133 | if (!_loading) 134 | { 135 | Properties["Persist Security Info"] = savePasswordCheckBox.Checked; 136 | } 137 | } 138 | 139 | private void TrimControlText(object sender, EventArgs e) 140 | { 141 | Control c = sender as Control; 142 | c.Text = c.Text.Trim(); 143 | } 144 | 145 | private string ServerProperty 146 | { 147 | get 148 | { 149 | if (!(Properties is OdbcConnectionProperties)) 150 | { 151 | return "Data Source"; 152 | } 153 | else 154 | { 155 | return "SERVER"; 156 | } 157 | } 158 | } 159 | 160 | private string UserNameProperty 161 | { 162 | get 163 | { 164 | if (!(Properties is OdbcConnectionProperties)) 165 | { 166 | return "User ID"; 167 | } 168 | else 169 | { 170 | return "UID"; 171 | } 172 | } 173 | } 174 | 175 | private string PasswordProperty 176 | { 177 | get 178 | { 179 | if (!(Properties is OdbcConnectionProperties)) 180 | { 181 | return "Password"; 182 | } 183 | else 184 | { 185 | return "PWD"; 186 | } 187 | } 188 | } 189 | 190 | private IDataConnectionProperties Properties 191 | { 192 | get 193 | { 194 | return _connectionProperties; 195 | } 196 | } 197 | 198 | private bool _loading; 199 | private IDataConnectionProperties _connectionProperties; 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/RTLAwareMessageBox.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Windows.Forms; 9 | using System.Globalization; 10 | 11 | namespace Microsoft.Data.ConnectionUI 12 | { 13 | internal sealed class RTLAwareMessageBox 14 | { 15 | private RTLAwareMessageBox() 16 | { 17 | } 18 | 19 | public static DialogResult Show(string caption, string text, MessageBoxIcon icon) 20 | { 21 | MessageBoxOptions options = 0; 22 | if (CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft) 23 | { 24 | options = MessageBoxOptions.RightAlign | MessageBoxOptions.RtlReading; 25 | } 26 | return MessageBox.Show(text, caption, MessageBoxButtons.OK, icon, MessageBoxDefaultButton.Button1, options); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/SqlConnectionProperties.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.ComponentModel; 10 | using System.Data.Common; 11 | using System.Data.SqlClient; 12 | using System.Text; 13 | 14 | namespace Microsoft.Data.ConnectionUI 15 | { 16 | public class SqlConnectionProperties : AdoDotNetConnectionProperties 17 | { 18 | public SqlConnectionProperties() 19 | : base("System.Data.SqlClient") 20 | { 21 | LocalReset(); 22 | } 23 | 24 | public override void Reset() 25 | { 26 | base.Reset(); 27 | LocalReset(); 28 | } 29 | 30 | public override bool IsComplete 31 | { 32 | get 33 | { 34 | if (!(ConnectionStringBuilder["Data Source"] is string) || 35 | (ConnectionStringBuilder["Data Source"] as string).Length == 0) 36 | { 37 | return false; 38 | } 39 | if (!(bool)ConnectionStringBuilder["Integrated Security"] && 40 | (!(ConnectionStringBuilder["User ID"] is string) || 41 | (ConnectionStringBuilder["User ID"] as string).Length == 0)) 42 | { 43 | return false; 44 | } 45 | return true; 46 | } 47 | } 48 | 49 | public override void Test() 50 | { 51 | string dataSource = ConnectionStringBuilder["Data Source"] as string; 52 | if (dataSource == null || dataSource.Length == 0) 53 | { 54 | throw new InvalidOperationException(Strings.SqlConnectionProperties_MustSpecifyDataSource); 55 | } 56 | string database = ConnectionStringBuilder["Initial Catalog"] as string; 57 | try 58 | { 59 | base.Test(); 60 | } 61 | catch (SqlException e) 62 | { 63 | if (e.Number == SqlError_CannotOpenDatabase && database != null && database.Length > 0) 64 | { 65 | throw new InvalidOperationException(Strings.SqlConnectionProperties_CannotTestNonExistentDatabase); 66 | } 67 | else 68 | { 69 | throw; 70 | } 71 | } 72 | } 73 | 74 | protected override PropertyDescriptor DefaultProperty 75 | { 76 | get 77 | { 78 | return GetProperties(new Attribute[0])["DataSource"]; 79 | } 80 | } 81 | 82 | protected override string ToTestString() 83 | { 84 | bool savedPooling = (bool)ConnectionStringBuilder["Pooling"]; 85 | bool wasDefault = !ConnectionStringBuilder.ShouldSerialize("Pooling"); 86 | ConnectionStringBuilder["Pooling"] = false; 87 | string testString = ConnectionStringBuilder.ConnectionString; 88 | ConnectionStringBuilder["Pooling"] = savedPooling; 89 | if (wasDefault) 90 | { 91 | ConnectionStringBuilder.Remove("Pooling"); 92 | } 93 | return testString; 94 | } 95 | 96 | protected override void Inspect(DbConnection connection) 97 | { 98 | if (connection.ServerVersion.StartsWith("07", StringComparison.Ordinal) || 99 | connection.ServerVersion.StartsWith("08", StringComparison.Ordinal)) 100 | { 101 | throw new NotSupportedException(Strings.SqlConnectionProperties_UnsupportedSqlVersion); 102 | } 103 | } 104 | 105 | private void LocalReset() 106 | { 107 | // We always start with integrated security turned on 108 | this["Integrated Security"] = true; 109 | } 110 | 111 | private const int SqlError_CannotOpenDatabase = 4060; 112 | } 113 | 114 | public class SqlFileConnectionProperties : SqlConnectionProperties 115 | { 116 | public SqlFileConnectionProperties() 117 | : this(null) 118 | { 119 | } 120 | 121 | public SqlFileConnectionProperties(string defaultInstanceName) 122 | { 123 | _defaultDataSource = "."; 124 | if (defaultInstanceName != null && defaultInstanceName.Length > 0) 125 | { 126 | _defaultDataSource += "\\" + defaultInstanceName; 127 | } 128 | else 129 | { 130 | DataSourceConverter conv = new DataSourceConverter(); 131 | System.ComponentModel.TypeConverter.StandardValuesCollection coll = conv.GetStandardValues(null); 132 | if (coll.Count > 0) 133 | { 134 | _defaultDataSource = coll[0] as string; 135 | } 136 | } 137 | LocalReset(); 138 | } 139 | 140 | public override void Reset() 141 | { 142 | base.Reset(); 143 | LocalReset(); 144 | } 145 | 146 | public override bool IsComplete 147 | { 148 | get 149 | { 150 | if (!base.IsComplete) 151 | { 152 | return false; 153 | } 154 | if (!(ConnectionStringBuilder["AttachDbFilename"] is string) || 155 | (ConnectionStringBuilder["AttachDbFilename"] as string).Length == 0) 156 | { 157 | return false; 158 | } 159 | return true; 160 | } 161 | } 162 | 163 | public override void Test() 164 | { 165 | string attachDbFilename = ConnectionStringBuilder["AttachDbFilename"] as string; 166 | try 167 | { 168 | if (attachDbFilename == null || attachDbFilename.Length == 0) 169 | { 170 | throw new InvalidOperationException(Strings.SqlFileConnectionProperties_NoFileSpecified); 171 | } 172 | ConnectionStringBuilder["AttachDbFilename"] = System.IO.Path.GetFullPath(attachDbFilename); 173 | if (!System.IO.File.Exists(ConnectionStringBuilder["AttachDbFilename"] as string)) 174 | { 175 | throw new InvalidOperationException(Strings.SqlFileConnectionProperties_CannotTestNonExistentMdf); 176 | } 177 | base.Test(); 178 | } 179 | catch (SqlException e) 180 | { 181 | if (e.Number == -2) // timeout 182 | { 183 | throw new ApplicationException(e.Errors[0].Message + Environment.NewLine + Strings.SqlFileConnectionProperties_TimeoutReasons); 184 | } 185 | throw; 186 | } 187 | finally 188 | { 189 | if (attachDbFilename != null && attachDbFilename.Length > 0) 190 | { 191 | ConnectionStringBuilder["AttachDbFilename"] = attachDbFilename; 192 | } 193 | } 194 | } 195 | 196 | protected override PropertyDescriptorCollection GetProperties(Attribute[] attributes) 197 | { 198 | PropertyDescriptorCollection descriptors = base.GetProperties(attributes); 199 | PropertyDescriptor dataSourceDescriptor = descriptors.Find("DataSource", true); 200 | if (dataSourceDescriptor != null) 201 | { 202 | int index = descriptors.IndexOf(dataSourceDescriptor); 203 | PropertyDescriptor[] descriptorArray = new PropertyDescriptor[descriptors.Count]; 204 | descriptors.CopyTo(descriptorArray, 0); 205 | descriptorArray[index] = new DynamicPropertyDescriptor(dataSourceDescriptor, new TypeConverterAttribute(typeof(DataSourceConverter))); 206 | (descriptorArray[index] as DynamicPropertyDescriptor).CanResetValueHandler = new CanResetValueHandler(CanResetDataSource); 207 | (descriptorArray[index] as DynamicPropertyDescriptor).ResetValueHandler = new ResetValueHandler(ResetDataSource); 208 | descriptors = new PropertyDescriptorCollection(descriptorArray, true); 209 | } 210 | return descriptors; 211 | } 212 | 213 | private void LocalReset() 214 | { 215 | this["Data Source"] = _defaultDataSource; 216 | this["User Instance"] = true; 217 | this["Connection Timeout"] = 30; 218 | } 219 | 220 | private bool CanResetDataSource(object component) 221 | { 222 | return !(this["Data Source"] is string) || !(this["Data Source"] as string).Equals(_defaultDataSource, StringComparison.OrdinalIgnoreCase); 223 | } 224 | 225 | private void ResetDataSource(object component) 226 | { 227 | this["Data Source"] = _defaultDataSource; 228 | } 229 | 230 | private class DataSourceConverter : StringConverter 231 | { 232 | public DataSourceConverter() 233 | { 234 | } 235 | 236 | public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 237 | { 238 | return true; 239 | } 240 | 241 | public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) 242 | { 243 | return true; 244 | } 245 | 246 | public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) 247 | { 248 | if (_standardValues == null) 249 | { 250 | string[] dataSources = null; 251 | 252 | if (HelpUtils.IsWow64()) 253 | { 254 | List dataSourceList = new List(); 255 | // Read 64 registry key of SQL Server Instances Names. 256 | dataSourceList.AddRange(HelpUtils.GetValueNamesWow64("SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL", NativeMethods.KEY_WOW64_64KEY | NativeMethods.KEY_QUERY_VALUE)); 257 | // Read 32 registry key of SQL Server Instances Names. 258 | dataSourceList.AddRange(HelpUtils.GetValueNamesWow64("SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL", NativeMethods.KEY_WOW64_32KEY | NativeMethods.KEY_QUERY_VALUE)); 259 | dataSources = dataSourceList.ToArray(); 260 | } 261 | else 262 | { 263 | // Look in the registry for all local SQL Server instances 264 | Win32.RegistryKey key = Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Microsoft SQL Server\\Instance Names\\SQL"); 265 | if (key != null) 266 | { 267 | using (key) 268 | { 269 | dataSources = key.GetValueNames(); 270 | } // key is Disposed here 271 | } 272 | } 273 | 274 | if (dataSources != null) 275 | { 276 | for (int i = 0; i < dataSources.Length; i++) 277 | { 278 | if (String.Equals(dataSources[i], "MSSQLSERVER", StringComparison.OrdinalIgnoreCase)) 279 | { 280 | dataSources[i] = "."; 281 | } 282 | else 283 | { 284 | dataSources[i] = ".\\" + dataSources[i]; 285 | } 286 | } 287 | _standardValues = new StandardValuesCollection(dataSources); 288 | } 289 | else 290 | { 291 | _standardValues = new StandardValuesCollection(new string[0]); 292 | } 293 | } 294 | return _standardValues; 295 | } 296 | 297 | private StandardValuesCollection _standardValues; 298 | } 299 | 300 | private string _defaultDataSource; 301 | } 302 | } 303 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/SqlExpressConnectionUIControl.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Data.ConnectionUI 2 | { 3 | public partial class SqlFileConnectionUIControl 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | protected override void Dispose(bool disposing) 14 | { 15 | if (disposing && (components != null)) 16 | { 17 | components.Dispose(); 18 | } 19 | base.Dispose(disposing); 20 | } 21 | 22 | #region Component Designer generated code 23 | 24 | /// 25 | /// Required method for Designer support - do not modify 26 | /// the contents of this method with the code editor. 27 | /// 28 | private void InitializeComponent() 29 | { 30 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SqlFileConnectionUIControl)); 31 | this.databaseFileLabel = new System.Windows.Forms.Label(); 32 | this.databaseFileTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 33 | this.databaseFileTextBox = new System.Windows.Forms.TextBox(); 34 | this.browseButton = new System.Windows.Forms.Button(); 35 | this.logonGroupBox = new System.Windows.Forms.GroupBox(); 36 | this.loginTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 37 | this.userNameLabel = new System.Windows.Forms.Label(); 38 | this.userNameTextBox = new System.Windows.Forms.TextBox(); 39 | this.passwordLabel = new System.Windows.Forms.Label(); 40 | this.passwordTextBox = new System.Windows.Forms.TextBox(); 41 | this.savePasswordCheckBox = new System.Windows.Forms.CheckBox(); 42 | this.sqlAuthenticationRadioButton = new System.Windows.Forms.RadioButton(); 43 | this.windowsAuthenticationRadioButton = new System.Windows.Forms.RadioButton(); 44 | this.databaseFileTableLayoutPanel.SuspendLayout(); 45 | this.logonGroupBox.SuspendLayout(); 46 | this.loginTableLayoutPanel.SuspendLayout(); 47 | this.SuspendLayout(); 48 | // 49 | // databaseFileLabel 50 | // 51 | resources.ApplyResources(this.databaseFileLabel, "databaseFileLabel"); 52 | this.databaseFileLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 53 | this.databaseFileLabel.Name = "databaseFileLabel"; 54 | // 55 | // databaseFileTableLayoutPanel 56 | // 57 | resources.ApplyResources(this.databaseFileTableLayoutPanel, "databaseFileTableLayoutPanel"); 58 | this.databaseFileTableLayoutPanel.Controls.Add(this.databaseFileTextBox, 0, 0); 59 | this.databaseFileTableLayoutPanel.Controls.Add(this.browseButton, 1, 0); 60 | this.databaseFileTableLayoutPanel.Name = "databaseFileTableLayoutPanel"; 61 | // 62 | // databaseFileTextBox 63 | // 64 | resources.ApplyResources(this.databaseFileTextBox, "databaseFileTextBox"); 65 | this.databaseFileTextBox.AutoCompleteMode = System.Windows.Forms.AutoCompleteMode.SuggestAppend; 66 | this.databaseFileTextBox.AutoCompleteSource = System.Windows.Forms.AutoCompleteSource.FileSystem; 67 | this.databaseFileTextBox.Name = "databaseFileTextBox"; 68 | this.databaseFileTextBox.Leave += new System.EventHandler(this.UpdateDatabaseFile); 69 | this.databaseFileTextBox.TextChanged += new System.EventHandler(this.SetDatabaseFile); 70 | // 71 | // browseButton 72 | // 73 | resources.ApplyResources(this.browseButton, "browseButton"); 74 | this.browseButton.Name = "browseButton"; 75 | this.browseButton.Click += new System.EventHandler(this.Browse); 76 | // 77 | // logonGroupBox 78 | // 79 | resources.ApplyResources(this.logonGroupBox, "logonGroupBox"); 80 | this.logonGroupBox.Controls.Add(this.loginTableLayoutPanel); 81 | this.logonGroupBox.Controls.Add(this.sqlAuthenticationRadioButton); 82 | this.logonGroupBox.Controls.Add(this.windowsAuthenticationRadioButton); 83 | this.logonGroupBox.FlatStyle = System.Windows.Forms.FlatStyle.System; 84 | this.logonGroupBox.Name = "logonGroupBox"; 85 | this.logonGroupBox.TabStop = false; 86 | // 87 | // loginTableLayoutPanel 88 | // 89 | resources.ApplyResources(this.loginTableLayoutPanel, "loginTableLayoutPanel"); 90 | this.loginTableLayoutPanel.Controls.Add(this.userNameLabel, 0, 0); 91 | this.loginTableLayoutPanel.Controls.Add(this.userNameTextBox, 1, 0); 92 | this.loginTableLayoutPanel.Controls.Add(this.passwordLabel, 0, 1); 93 | this.loginTableLayoutPanel.Controls.Add(this.passwordTextBox, 1, 1); 94 | this.loginTableLayoutPanel.Controls.Add(this.savePasswordCheckBox, 1, 2); 95 | this.loginTableLayoutPanel.Name = "loginTableLayoutPanel"; 96 | // 97 | // userNameLabel 98 | // 99 | resources.ApplyResources(this.userNameLabel, "userNameLabel"); 100 | this.userNameLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 101 | this.userNameLabel.Name = "userNameLabel"; 102 | // 103 | // userNameTextBox 104 | // 105 | resources.ApplyResources(this.userNameTextBox, "userNameTextBox"); 106 | this.userNameTextBox.Name = "userNameTextBox"; 107 | this.userNameTextBox.Leave += new System.EventHandler(this.TrimControlText); 108 | this.userNameTextBox.TextChanged += new System.EventHandler(this.SetUserName); 109 | // 110 | // passwordLabel 111 | // 112 | resources.ApplyResources(this.passwordLabel, "passwordLabel"); 113 | this.passwordLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 114 | this.passwordLabel.Name = "passwordLabel"; 115 | // 116 | // passwordTextBox 117 | // 118 | resources.ApplyResources(this.passwordTextBox, "passwordTextBox"); 119 | this.passwordTextBox.Name = "passwordTextBox"; 120 | this.passwordTextBox.UseSystemPasswordChar = true; 121 | this.passwordTextBox.TextChanged += new System.EventHandler(this.SetPassword); 122 | // 123 | // savePasswordCheckBox 124 | // 125 | resources.ApplyResources(this.savePasswordCheckBox, "savePasswordCheckBox"); 126 | this.savePasswordCheckBox.Name = "savePasswordCheckBox"; 127 | this.savePasswordCheckBox.CheckedChanged += new System.EventHandler(this.SetSavePassword); 128 | // 129 | // sqlAuthenticationRadioButton 130 | // 131 | resources.ApplyResources(this.sqlAuthenticationRadioButton, "sqlAuthenticationRadioButton"); 132 | this.sqlAuthenticationRadioButton.Name = "sqlAuthenticationRadioButton"; 133 | this.sqlAuthenticationRadioButton.CheckedChanged += new System.EventHandler(this.SetAuthenticationOption); 134 | // 135 | // windowsAuthenticationRadioButton 136 | // 137 | resources.ApplyResources(this.windowsAuthenticationRadioButton, "windowsAuthenticationRadioButton"); 138 | this.windowsAuthenticationRadioButton.Name = "windowsAuthenticationRadioButton"; 139 | this.windowsAuthenticationRadioButton.CheckedChanged += new System.EventHandler(this.SetAuthenticationOption); 140 | // 141 | // SqlFileConnectionUIControl 142 | // 143 | resources.ApplyResources(this, "$this"); 144 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 145 | this.Controls.Add(this.logonGroupBox); 146 | this.Controls.Add(this.databaseFileTableLayoutPanel); 147 | this.Controls.Add(this.databaseFileLabel); 148 | this.MinimumSize = new System.Drawing.Size(300, 191); 149 | this.Name = "SqlFileConnectionUIControl"; 150 | this.databaseFileTableLayoutPanel.ResumeLayout(false); 151 | this.databaseFileTableLayoutPanel.PerformLayout(); 152 | this.logonGroupBox.ResumeLayout(false); 153 | this.logonGroupBox.PerformLayout(); 154 | this.loginTableLayoutPanel.ResumeLayout(false); 155 | this.loginTableLayoutPanel.PerformLayout(); 156 | this.ResumeLayout(false); 157 | this.PerformLayout(); 158 | 159 | } 160 | 161 | #endregion 162 | 163 | private System.Windows.Forms.Label databaseFileLabel; 164 | private System.Windows.Forms.TableLayoutPanel databaseFileTableLayoutPanel; 165 | private System.Windows.Forms.TextBox databaseFileTextBox; 166 | private System.Windows.Forms.Button browseButton; 167 | private System.Windows.Forms.GroupBox logonGroupBox; 168 | private System.Windows.Forms.RadioButton windowsAuthenticationRadioButton; 169 | private System.Windows.Forms.RadioButton sqlAuthenticationRadioButton; 170 | private System.Windows.Forms.TableLayoutPanel loginTableLayoutPanel; 171 | private System.Windows.Forms.Label userNameLabel; 172 | private System.Windows.Forms.TextBox userNameTextBox; 173 | private System.Windows.Forms.Label passwordLabel; 174 | private System.Windows.Forms.TextBox passwordTextBox; 175 | private System.Windows.Forms.CheckBox savePasswordCheckBox; 176 | 177 | } 178 | } 179 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/SqlExpressConnectionUIControl.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Drawing; 9 | using System.Diagnostics; 10 | using System.Windows.Forms; 11 | 12 | namespace Microsoft.Data.ConnectionUI 13 | { 14 | public partial class SqlFileConnectionUIControl : UserControl, IDataConnectionUIControl 15 | { 16 | public SqlFileConnectionUIControl() 17 | { 18 | InitializeComponent(); 19 | RightToLeft = RightToLeft.Inherit; 20 | 21 | int requiredHeight = LayoutUtils.GetPreferredCheckBoxHeight(savePasswordCheckBox); 22 | if (savePasswordCheckBox.Height < requiredHeight) 23 | { 24 | savePasswordCheckBox.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom; 25 | loginTableLayoutPanel.Height += loginTableLayoutPanel.Margin.Bottom; 26 | loginTableLayoutPanel.Margin = new Padding(loginTableLayoutPanel.Margin.Left, loginTableLayoutPanel.Margin.Top, loginTableLayoutPanel.Margin.Right, 0); 27 | } 28 | } 29 | 30 | public void Initialize(IDataConnectionProperties connectionProperties) 31 | { 32 | if (!(connectionProperties is SqlFileConnectionProperties)) 33 | { 34 | throw new ArgumentException(Strings.SqlFileConnectionUIControl_InvalidConnectionProperties); 35 | } 36 | 37 | _connectionProperties = connectionProperties; 38 | } 39 | 40 | public void LoadProperties() 41 | { 42 | _loading = true; 43 | 44 | databaseFileTextBox.Text = Properties["AttachDbFilename"] as string; 45 | string myDocumentsDir = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); 46 | if (databaseFileTextBox.Text.StartsWith(myDocumentsDir, StringComparison.OrdinalIgnoreCase)) 47 | { 48 | databaseFileTextBox.Text = databaseFileTextBox.Text.Substring(myDocumentsDir.Length + 1); 49 | } 50 | if ((bool)Properties["Integrated Security"]) 51 | { 52 | windowsAuthenticationRadioButton.Checked = true; 53 | } 54 | else 55 | { 56 | sqlAuthenticationRadioButton.Checked = true; 57 | } 58 | userNameTextBox.Text = Properties["User ID"] as string; 59 | passwordTextBox.Text = Properties["Password"] as string; 60 | savePasswordCheckBox.Checked = (bool)Properties["Persist Security Info"]; 61 | 62 | _loading = false; 63 | } 64 | 65 | // Simulate RTL mirroring 66 | protected override void OnRightToLeftChanged(EventArgs e) 67 | { 68 | base.OnRightToLeftChanged(e); 69 | if (ParentForm != null && 70 | ParentForm.RightToLeftLayout == true && 71 | RightToLeft == RightToLeft.Yes) 72 | { 73 | LayoutUtils.MirrorControl(databaseFileLabel, databaseFileTableLayoutPanel); 74 | LayoutUtils.MirrorControl(windowsAuthenticationRadioButton); 75 | LayoutUtils.MirrorControl(sqlAuthenticationRadioButton); 76 | LayoutUtils.MirrorControl(loginTableLayoutPanel); 77 | } 78 | else 79 | { 80 | LayoutUtils.UnmirrorControl(loginTableLayoutPanel); 81 | LayoutUtils.UnmirrorControl(sqlAuthenticationRadioButton); 82 | LayoutUtils.UnmirrorControl(windowsAuthenticationRadioButton); 83 | LayoutUtils.UnmirrorControl(databaseFileLabel, databaseFileTableLayoutPanel); 84 | } 85 | } 86 | 87 | protected override void ScaleControl(SizeF factor, BoundsSpecified specified) 88 | { 89 | Size baseSize = Size; 90 | MinimumSize = Size.Empty; 91 | base.ScaleControl(factor, specified); 92 | MinimumSize = new Size( 93 | (int)Math.Round((float)baseSize.Width * factor.Width), 94 | (int)Math.Round((float)baseSize.Height * factor.Height)); 95 | } 96 | 97 | protected override void OnParentChanged(EventArgs e) 98 | { 99 | base.OnParentChanged(e); 100 | if (Parent == null) 101 | { 102 | OnFontChanged(e); 103 | } 104 | } 105 | 106 | private void SetDatabaseFile(object sender, System.EventArgs e) 107 | { 108 | if (!_loading) 109 | { 110 | Properties["AttachDbFilename"] = (databaseFileTextBox.Text.Trim().Length > 0) ? databaseFileTextBox.Text.Trim() : null; 111 | } 112 | } 113 | 114 | private void UpdateDatabaseFile(object sender, System.EventArgs e) 115 | { 116 | if (!_loading) 117 | { 118 | string attachDbFilename = (databaseFileTextBox.Text.Trim().Length > 0) ? databaseFileTextBox.Text.Trim() : null; 119 | if (attachDbFilename != null) 120 | { 121 | if (!attachDbFilename.EndsWith(".mdf", StringComparison.OrdinalIgnoreCase)) 122 | { 123 | attachDbFilename += ".mdf"; 124 | } 125 | try 126 | { 127 | if (!System.IO.Path.IsPathRooted(attachDbFilename)) 128 | { 129 | // Simulate a default directory as My Documents by appending this to the front 130 | attachDbFilename = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), attachDbFilename); 131 | } 132 | } 133 | catch { } 134 | } 135 | Properties["AttachDbFilename"] = attachDbFilename; 136 | } 137 | } 138 | 139 | private void Browse(object sender, System.EventArgs e) 140 | { 141 | OpenFileDialog fileDialog = new OpenFileDialog(); 142 | fileDialog.Title = Strings.SqlConnectionUIControl_BrowseFileTitle; 143 | fileDialog.Multiselect = false; 144 | fileDialog.CheckFileExists = false; 145 | fileDialog.RestoreDirectory = true; 146 | fileDialog.Filter = Strings.SqlConnectionUIControl_BrowseFileFilter; 147 | fileDialog.DefaultExt = Strings.SqlConnectionUIControl_BrowseFileDefaultExt; 148 | fileDialog.FileName = Properties["AttachDbFilename"] as string; 149 | if (this.Container != null) 150 | { 151 | this.Container.Add(fileDialog); 152 | } 153 | try 154 | { 155 | DialogResult result = fileDialog.ShowDialog(ParentForm); 156 | if (result == DialogResult.OK) 157 | { 158 | databaseFileTextBox.Text = fileDialog.FileName.Trim(); 159 | } 160 | } 161 | finally 162 | { 163 | if (this.Container != null) 164 | { 165 | this.Container.Remove(fileDialog); 166 | } 167 | fileDialog.Dispose(); 168 | } 169 | } 170 | 171 | private void SetAuthenticationOption(object sender, EventArgs e) 172 | { 173 | if (windowsAuthenticationRadioButton.Checked) 174 | { 175 | if (!_loading) 176 | { 177 | Properties["Integrated Security"] = true; 178 | Properties.Reset("User ID"); 179 | Properties.Reset("Password"); 180 | Properties.Reset("Persist Security Info"); 181 | } 182 | loginTableLayoutPanel.Enabled = false; 183 | } 184 | else /* if (sqlAuthenticationRadioButton.Checked) */ 185 | { 186 | if (!_loading) 187 | { 188 | Properties["Integrated Security"] = false; 189 | SetUserName(sender, e); 190 | SetPassword(sender, e); 191 | SetSavePassword(sender, e); 192 | } 193 | loginTableLayoutPanel.Enabled = true; 194 | } 195 | } 196 | 197 | private void SetUserName(object sender, EventArgs e) 198 | { 199 | if (!_loading) 200 | { 201 | Properties["User ID"] = (userNameTextBox.Text.Trim().Length > 0) ? userNameTextBox.Text.Trim() : null; 202 | } 203 | } 204 | 205 | private void SetPassword(object sender, EventArgs e) 206 | { 207 | if (!_loading) 208 | { 209 | Properties["Password"] = (passwordTextBox.Text.Length > 0) ? passwordTextBox.Text : null; 210 | passwordTextBox.Text = passwordTextBox.Text; // forces reselection of all text 211 | } 212 | } 213 | 214 | private void SetSavePassword(object sender, EventArgs e) 215 | { 216 | if (!_loading) 217 | { 218 | Properties["Persist Security Info"] = savePasswordCheckBox.Checked; 219 | } 220 | } 221 | 222 | private void TrimControlText(object sender, EventArgs e) 223 | { 224 | Control c = sender as Control; 225 | c.Text = c.Text.Trim(); 226 | } 227 | 228 | private IDataConnectionProperties Properties 229 | { 230 | get 231 | { 232 | return _connectionProperties; 233 | } 234 | } 235 | 236 | private bool _loading; 237 | private IDataConnectionProperties _connectionProperties; 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /Source/ConnectionUIDialog/UserPreferencedChangedHandler.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Drawing; 9 | using System.Diagnostics; 10 | using System.Windows.Forms; 11 | using System.ComponentModel; 12 | using System.Windows.Forms.Design; 13 | using Microsoft.Win32; 14 | 15 | namespace Microsoft.Data.ConnectionUI 16 | { 17 | internal sealed class UserPreferenceChangedHandler : IComponent 18 | { 19 | public UserPreferenceChangedHandler(Form form) 20 | { 21 | Debug.Assert(form != null); 22 | SystemEvents.UserPreferenceChanged += new UserPreferenceChangedEventHandler(HandleUserPreferenceChanged); 23 | _form = form; 24 | } 25 | 26 | ~UserPreferenceChangedHandler() 27 | { 28 | Dispose(false); 29 | } 30 | 31 | public ISite Site 32 | { 33 | get 34 | { 35 | return _form.Site; 36 | } 37 | set 38 | { 39 | // This shouldn't be called 40 | } 41 | } 42 | 43 | public event EventHandler Disposed; 44 | 45 | public void Dispose() 46 | { 47 | Dispose(true); 48 | GC.SuppressFinalize(this); 49 | } 50 | 51 | private void HandleUserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e) 52 | { 53 | // Need to update the font 54 | IUIService uiService = (_form.Site != null) ? _form.Site.GetService(typeof(IUIService)) as IUIService : null; 55 | if (uiService != null) 56 | { 57 | Font newFont = uiService.Styles["DialogFont"] as Font; 58 | if (newFont != null) 59 | { 60 | _form.Font = newFont; 61 | } 62 | } 63 | } 64 | 65 | private void Dispose(bool disposing) 66 | { 67 | if (disposing) 68 | { 69 | SystemEvents.UserPreferenceChanged -= new UserPreferenceChangedEventHandler(HandleUserPreferenceChanged); 70 | if (Disposed != null) 71 | { 72 | Disposed(this, EventArgs.Empty); 73 | } 74 | } 75 | } 76 | 77 | private Form _form; 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /Source/References/Microsoft.SqlServerCe.Client.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kjbartel/ConnectionDialog/3eb8a29fe3103288ea5084140244e482deb16a13/Source/References/Microsoft.SqlServerCe.Client.dll -------------------------------------------------------------------------------- /Source/Sample.VB/DataConnectionConfiguration.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' Copyright (c) Microsoft Corporation. All rights reserved. 4 | ' 5 | '------------------------------------------------------------------------------ 6 | Imports System 7 | Imports System.Collections.Generic 8 | Imports System.Linq 9 | Imports System.Text 10 | Imports System.Xml.Linq 11 | Imports System.IO 12 | 13 | Imports Microsoft.Data.ConnectionUI 14 | 15 | 16 | 17 | Namespace Microsoft.Data.ConnectionUI.VB 18 | ''' 19 | ''' Provide a default implementation for the storage of DataConnection Dialog UI configuration. 20 | ''' 21 | Public Class DataConnectionConfiguration 22 | Implements IDataConnectionConfiguration 23 | Private Const configFileName As String = "DataConnection.xml" 24 | Private fullFilePath As String = Nothing 25 | Private xDoc As XDocument = Nothing 26 | 27 | ' Available data sources: 28 | Private dataSources As IDictionary(Of String, DataSource) 29 | 30 | ' Available data providers: 31 | Private dataProviders As IDictionary(Of String, DataProvider) 32 | 33 | ''' 34 | ''' Constructor 35 | ''' 36 | ''' Configuration file path. 37 | Public Sub New(ByVal path As String) 38 | If Not [String].IsNullOrEmpty(path) Then 39 | fullFilePath = System.IO.Path.GetFullPath(System.IO.Path.Combine(path, configFileName)) 40 | Else 41 | fullFilePath = System.IO.Path.Combine(System.Environment.CurrentDirectory, configFileName) 42 | End If 43 | If Not [String].IsNullOrEmpty(fullFilePath) AndAlso File.Exists(fullFilePath) Then 44 | xDoc = XDocument.Load(fullFilePath) 45 | Else 46 | xDoc = New XDocument() 47 | xDoc.Add(New XElement("ConnectionDialog", New XElement("DataSourceSelection"))) 48 | End If 49 | 50 | Me.RootElement = xDoc.Root 51 | End Sub 52 | 53 | Private _RootElement As XElement 54 | Public Property RootElement() As XElement 55 | Get 56 | Return _RootElement 57 | End Get 58 | Set(ByVal value As XElement) 59 | _RootElement = value 60 | End Set 61 | End Property 62 | 63 | Public Sub LoadConfiguration(ByVal dialog As DataConnectionDialog) 64 | dialog.DataSources.Add(DataSource.SqlDataSource) 65 | dialog.DataSources.Add(DataSource.SqlFileDataSource) 66 | dialog.DataSources.Add(DataSource.OracleDataSource) 67 | dialog.DataSources.Add(DataSource.AccessDataSource) 68 | dialog.DataSources.Add(DataSource.OdbcDataSource) 69 | dialog.DataSources.Add(SqlCe.SqlCeDataSource) 70 | 71 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.SqlDataProvider) 72 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.OracleDataProvider) 73 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.OleDBDataProvider) 74 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.OdbcDataProvider) 75 | dialog.DataSources.Add(dialog.UnspecifiedDataSource) 76 | 77 | Me.dataSources = New Dictionary(Of String, DataSource)() 78 | Me.dataSources.Add(DataSource.SqlDataSource.Name, DataSource.SqlDataSource) 79 | Me.dataSources.Add(DataSource.SqlFileDataSource.Name, DataSource.SqlFileDataSource) 80 | Me.dataSources.Add(DataSource.OracleDataSource.Name, DataSource.OracleDataSource) 81 | Me.dataSources.Add(DataSource.AccessDataSource.Name, DataSource.AccessDataSource) 82 | Me.dataSources.Add(DataSource.OdbcDataSource.Name, DataSource.OdbcDataSource) 83 | Me.dataSources.Add(SqlCe.SqlCeDataSource.Name, SqlCe.SqlCeDataSource) 84 | Me.dataSources.Add(dialog.UnspecifiedDataSource.DisplayName, dialog.UnspecifiedDataSource) 85 | 86 | Me.dataProviders = New Dictionary(Of String, DataProvider)() 87 | Me.dataProviders.Add(DataProvider.SqlDataProvider.Name, DataProvider.SqlDataProvider) 88 | Me.dataProviders.Add(DataProvider.OracleDataProvider.Name, DataProvider.OracleDataProvider) 89 | Me.dataProviders.Add(DataProvider.OleDBDataProvider.Name, DataProvider.OleDBDataProvider) 90 | Me.dataProviders.Add(DataProvider.OdbcDataProvider.Name, DataProvider.OdbcDataProvider) 91 | Me.dataProviders.Add(SqlCe.SqlCeDataProvider.Name, SqlCe.SqlCeDataProvider) 92 | 93 | 94 | Dim ds As DataSource = Nothing 95 | Dim dsName As String = Me.GetSelectedSource() 96 | If Not [String].IsNullOrEmpty(dsName) AndAlso Me.dataSources.TryGetValue(dsName, ds) Then 97 | dialog.SelectedDataSource = ds 98 | End If 99 | 100 | Dim dp As DataProvider = Nothing 101 | Dim dpName As String = Me.GetSelectedProvider() 102 | If Not [String].IsNullOrEmpty(dpName) AndAlso Me.dataProviders.TryGetValue(dpName, dp) Then 103 | dialog.SelectedDataProvider = dp 104 | End If 105 | End Sub 106 | 107 | Public Sub SaveConfiguration(ByVal dcd As DataConnectionDialog) 108 | If dcd.SaveSelection Then 109 | Dim ds As DataSource = dcd.SelectedDataSource 110 | If ds IsNot Nothing Then 111 | If ds Is dcd.UnspecifiedDataSource Then 112 | Me.SaveSelectedSource(ds.DisplayName) 113 | Else 114 | Me.SaveSelectedSource(ds.Name) 115 | End If 116 | End If 117 | Dim dp As DataProvider = dcd.SelectedDataProvider 118 | If dp IsNot Nothing Then 119 | Me.SaveSelectedProvider(dp.Name) 120 | End If 121 | 122 | xDoc.Save(fullFilePath) 123 | End If 124 | End Sub 125 | 126 | Public Function GetSelectedSource() As String Implements IDataConnectionConfiguration.GetSelectedSource 127 | Try 128 | Dim xElem As XElement = Me.RootElement.Element("DataSourceSelection") 129 | Dim sourceElem As XElement = xElem.Element("SelectedSource") 130 | If sourceElem IsNot Nothing Then 131 | Return TryCast(sourceElem.Value, String) 132 | End If 133 | Catch 134 | Return Nothing 135 | End Try 136 | Return Nothing 137 | End Function 138 | 139 | Public Function GetSelectedProvider() As String Implements IDataConnectionConfiguration.GetSelectedProvider 140 | Try 141 | Dim xElem As XElement = Me.RootElement.Element("DataSourceSelection") 142 | Dim providerElem As XElement = xElem.Element("SelectedProvider") 143 | If providerElem IsNot Nothing Then 144 | Return TryCast(providerElem.Value, String) 145 | End If 146 | Catch 147 | Return Nothing 148 | End Try 149 | Return Nothing 150 | End Function 151 | 152 | Public Sub SaveSelectedSource(ByVal source As String) Implements IDataConnectionConfiguration.SaveSelectedSource 153 | If Not [String].IsNullOrEmpty(source) Then 154 | Try 155 | Dim xElem As XElement = Me.RootElement.Element("DataSourceSelection") 156 | Dim sourceElem As XElement = xElem.Element("SelectedSource") 157 | If sourceElem IsNot Nothing Then 158 | sourceElem.Value = source 159 | Else 160 | xElem.Add(New XElement("SelectedSource", source)) 161 | End If 162 | Catch 163 | End Try 164 | 165 | End If 166 | End Sub 167 | 168 | Public Sub SaveSelectedProvider(ByVal provider As String) Implements IDataConnectionConfiguration.SaveSelectedProvider 169 | If Not [String].IsNullOrEmpty(provider) Then 170 | Try 171 | Dim xElem As XElement = Me.RootElement.Element("DataSourceSelection") 172 | Dim sourceElem As XElement = xElem.Element("SelectedProvider") 173 | If sourceElem IsNot Nothing Then 174 | sourceElem.Value = provider 175 | Else 176 | xElem.Add(New XElement("SelectedProvider", provider)) 177 | End If 178 | Catch 179 | End Try 180 | End If 181 | End Sub 182 | End Class 183 | End Namespace -------------------------------------------------------------------------------- /Source/Sample.VB/IDataConnectionConfiguration.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' Copyright (c) Microsoft Corporation. All rights reserved. 4 | ' 5 | '------------------------------------------------------------------------------ 6 | 7 | Imports System 8 | Imports System.Collections.Generic 9 | Imports System.Text 10 | 11 | Namespace Microsoft.Data.ConnectionUI.VB 12 | 13 | Public Interface IDataConnectionConfiguration 14 | Function GetSelectedSource() As String 15 | Sub SaveSelectedSource(ByVal provider As String) 16 | 17 | Function GetSelectedProvider() As String 18 | Sub SaveSelectedProvider(ByVal provider As String) 19 | End Interface 20 | 21 | End Namespace -------------------------------------------------------------------------------- /Source/Sample.VB/Microsoft.Data.ConnectionUI.Sample.VB.vbproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {CF22916C-6B3C-4D67-AD2E-94A730526539} 9 | Exe 10 | Microsoft.Data.ConnectionUI.Sample.VB.Microsoft.Data.ConnectionUI.VB.Sample 11 | Microsoft.Data.ConnectionUI.Sample.VB 12 | Microsoft.Data.ConnectionUI.Sample.VB 13 | 512 14 | Console 15 | v3.5 16 | On 17 | Binary 18 | Off 19 | On 20 | 21 | 22 | 23 | 24 | 3.5 25 | 26 | 27 | true 28 | full 29 | true 30 | true 31 | bin\Debug\ 32 | Microsoft.Data.ConnectionUI.Sample.VB.xml 33 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022,42353,42354,42355 34 | 35 | 36 | pdbonly 37 | false 38 | true 39 | true 40 | bin\Release\ 41 | Microsoft.Data.ConnectionUI.Sample.VB.xml 42 | 42016,41999,42017,42018,42019,42032,42036,42020,42021,42022,42353,42354,42355 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 3.5 52 | 53 | 54 | 3.5 55 | 56 | 57 | 3.5 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | True 77 | Application.myapp 78 | 79 | 80 | True 81 | True 82 | Resources.resx 83 | 84 | 85 | True 86 | Settings.settings 87 | True 88 | 89 | 90 | 91 | 92 | VbMyResourcesResXFileCodeGenerator 93 | Resources.Designer.vb 94 | My.Resources 95 | Designer 96 | 97 | 98 | 99 | 100 | MyApplicationCodeGenerator 101 | Application.Designer.vb 102 | 103 | 104 | SettingsSingleFileGenerator 105 | My 106 | Settings.Designer.vb 107 | 108 | 109 | 110 | 111 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA} 112 | Microsoft.Data.ConnectionUI.Dialog 113 | 114 | 115 | {139729CD-0F06-48E8-9F4A-08E78BB6575F} 116 | Microsoft.Data.ConnectionUI 117 | 118 | 119 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31} 120 | Microsoft.Data.ConnectionUI.SqlCeDataProvider 121 | 122 | 123 | 124 | 131 | -------------------------------------------------------------------------------- /Source/Sample.VB/My Project/Application.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.17379 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | -------------------------------------------------------------------------------- /Source/Sample.VB/My Project/Application.myapp: -------------------------------------------------------------------------------- 1 |  2 | 3 | false 4 | false 5 | 0 6 | true 7 | 0 8 | 2 9 | true 10 | 11 | -------------------------------------------------------------------------------- /Source/Sample.VB/My Project/AssemblyInfo.vb: -------------------------------------------------------------------------------- 1 | Imports System 2 | Imports System.Reflection 3 | Imports System.Runtime.InteropServices 4 | 5 | ' General Information about an assembly is controlled through the following 6 | ' set of attributes. Change these attribute values to modify the information 7 | ' associated with an assembly. 8 | 9 | ' Review the values of the assembly attributes 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 'The following GUID is for the ID of the typelib if this project is exposed to COM 21 | 22 | 23 | ' Version information for an assembly consists of the following four values: 24 | ' 25 | ' Major Version 26 | ' Minor Version 27 | ' Build Number 28 | ' Revision 29 | ' 30 | ' You can specify all the values or you can default the Build and Revision Numbers 31 | ' by using the '*' as shown below: 32 | ' 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Source/Sample.VB/My Project/Resources.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.17379 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | Imports System 15 | 16 | Namespace My.Resources 17 | 18 | 'This class was auto-generated by the StronglyTypedResourceBuilder 19 | 'class via a tool like ResGen or Visual Studio. 20 | 'To add or remove a member, edit your .ResX file then rerun ResGen 21 | 'with the /str option, or rebuild your VS project. 22 | ''' 23 | ''' A strongly-typed resource class, for looking up localized strings, etc. 24 | ''' 25 | _ 29 | Friend Module Resources 30 | 31 | Private resourceMan As Global.System.Resources.ResourceManager 32 | 33 | Private resourceCulture As Global.System.Globalization.CultureInfo 34 | 35 | ''' 36 | ''' Returns the cached ResourceManager instance used by this class. 37 | ''' 38 | _ 39 | Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager 40 | Get 41 | If Object.ReferenceEquals(resourceMan, Nothing) Then 42 | Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("Microsoft.Data.ConnectionUI.Sample.VB.Resources", GetType(Resources).Assembly) 43 | resourceMan = temp 44 | End If 45 | Return resourceMan 46 | End Get 47 | End Property 48 | 49 | ''' 50 | ''' Overrides the current thread's CurrentUICulture property for all 51 | ''' resource lookups using this strongly typed resource class. 52 | ''' 53 | _ 54 | Friend Property Culture() As Global.System.Globalization.CultureInfo 55 | Get 56 | Return resourceCulture 57 | End Get 58 | Set 59 | resourceCulture = value 60 | End Set 61 | End Property 62 | End Module 63 | End Namespace 64 | -------------------------------------------------------------------------------- /Source/Sample.VB/My Project/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /Source/Sample.VB/My Project/Settings.Designer.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' This code was generated by a tool. 4 | ' Runtime Version:4.0.30319.17379 5 | ' 6 | ' Changes to this file may cause incorrect behavior and will be lost if 7 | ' the code is regenerated. 8 | ' 9 | '------------------------------------------------------------------------------ 10 | 11 | Option Strict On 12 | Option Explicit On 13 | 14 | 15 | Namespace My 16 | 17 | _ 20 | Partial Friend NotInheritable Class MySettings 21 | Inherits Global.System.Configuration.ApplicationSettingsBase 22 | 23 | Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings()),MySettings) 24 | 25 | #Region "My.Settings Auto-Save Functionality" 26 | #If _MyType = "WindowsForms" Then 27 | Private Shared addedHandler As Boolean 28 | 29 | Private Shared addedHandlerLockObject As New Object 30 | 31 | _ 32 | Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs) 33 | If My.Application.SaveMySettingsOnExit Then 34 | My.Settings.Save() 35 | End If 36 | End Sub 37 | #End If 38 | #End Region 39 | 40 | Public Shared ReadOnly Property [Default]() As MySettings 41 | Get 42 | 43 | #If _MyType = "WindowsForms" Then 44 | If Not addedHandler Then 45 | SyncLock addedHandlerLockObject 46 | If Not addedHandler Then 47 | AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings 48 | addedHandler = True 49 | End If 50 | End SyncLock 51 | End If 52 | #End If 53 | Return defaultInstance 54 | End Get 55 | End Property 56 | End Class 57 | End Namespace 58 | 59 | Namespace My 60 | 61 | _ 64 | Friend Module MySettingsProperty 65 | 66 | _ 67 | Friend ReadOnly Property Settings() As Global.Microsoft.Data.ConnectionUI.Sample.VB.My.MySettings 68 | Get 69 | Return Global.Microsoft.Data.ConnectionUI.Sample.VB.My.MySettings.Default 70 | End Get 71 | End Property 72 | End Module 73 | End Namespace 74 | -------------------------------------------------------------------------------- /Source/Sample.VB/My Project/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Source/Sample.VB/Sample.vb: -------------------------------------------------------------------------------- 1 | '------------------------------------------------------------------------------ 2 | ' 3 | ' Copyright (c) Microsoft Corporation. All rights reserved. 4 | ' 5 | '------------------------------------------------------------------------------ 6 | 7 | Imports System 8 | Imports System.Collections.Generic 9 | Imports System.Data.SqlClient 10 | Imports System.Linq 11 | Imports System.Text 12 | Imports System.Windows.Forms 13 | 14 | Imports Microsoft.Data.ConnectionUI 15 | 16 | Namespace Microsoft.Data.ConnectionUI.VB 17 | Module Sample 18 | ' Sample 1: 19 | _ 20 | Public Sub Main(ByVal args As String()) 21 | Dim dcd As New DataConnectionDialog() 22 | Dim dcs As New DataConnectionConfiguration(Nothing) 23 | dcs.LoadConfiguration(dcd) 24 | 25 | If DataConnectionDialog.Show(dcd) = DialogResult.OK Then 26 | ' load tables 27 | Using connection As New SqlConnection(dcd.ConnectionString) 28 | connection.Open() 29 | Dim cmd As New SqlCommand("SELECT * FROM sys.Tables", connection) 30 | 31 | Using reader As SqlDataReader = cmd.ExecuteReader() 32 | While reader.Read() 33 | Console.WriteLine(reader.HasRows) 34 | End While 35 | 36 | End Using 37 | End Using 38 | End If 39 | 40 | dcs.SaveConfiguration(dcd) 41 | End Sub 42 | 43 | '' Sample 2: 44 | ' _ 45 | 'Public Sub Main(ByVal args As String()) 46 | ' Dim dcd As New DataConnectionDialog() 47 | ' Dim dcs As New DataConnectionConfiguration(Nothing) 48 | ' dcs.LoadConfiguration(dcd) 49 | ' dcd.ConnectionString = "Data Source=ziz-vspro-sql05;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=Admin_007"; 50 | 51 | 52 | ' If DataConnectionDialog.Show(dcd) = DialogResult.OK Then 53 | ' ' load tables 54 | ' Using connection As New SqlConnection(dcd.ConnectionString) 55 | ' connection.Open() 56 | ' Dim cmd As New SqlCommand("SELECT * FROM sys.Tables", connection) 57 | 58 | ' Using reader As SqlDataReader = cmd.ExecuteReader() 59 | ' While reader.Read() 60 | ' Console.WriteLine(reader.HasRows) 61 | ' End While 62 | 63 | ' End Using 64 | ' End Using 65 | ' End If 66 | 67 | ' dcs.SaveConfiguration(dcd) 68 | 'End Sub 69 | End Module 70 | End Namespace -------------------------------------------------------------------------------- /Source/Sample/DataConnectionConfiguration.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Text; 10 | using System.Xml.Linq; 11 | using System.IO; 12 | 13 | namespace Microsoft.Data.ConnectionUI 14 | { 15 | /// 16 | /// Provide a default implementation for the storage of DataConnection Dialog UI configuration. 17 | /// 18 | public class DataConnectionConfiguration : IDataConnectionConfiguration 19 | { 20 | private const string configFileName = @"DataConnection.xml"; 21 | private string fullFilePath = null; 22 | private XDocument xDoc = null; 23 | 24 | // Available data sources: 25 | private IDictionary dataSources; 26 | 27 | // Available data providers: 28 | private IDictionary dataProviders; 29 | 30 | /// 31 | /// Constructor 32 | /// 33 | /// Configuration file path. 34 | public DataConnectionConfiguration(string path) 35 | { 36 | if (!String.IsNullOrEmpty(path)) 37 | { 38 | fullFilePath = Path.GetFullPath(Path.Combine(path, configFileName)); 39 | } 40 | else 41 | { 42 | fullFilePath = Path.Combine(System.Environment.CurrentDirectory, configFileName); 43 | } 44 | if (!String.IsNullOrEmpty(fullFilePath) && File.Exists(fullFilePath)) 45 | { 46 | xDoc = XDocument.Load(fullFilePath); 47 | } 48 | else 49 | { 50 | xDoc = new XDocument(); 51 | xDoc.Add(new XElement("ConnectionDialog", new XElement("DataSourceSelection"))); 52 | } 53 | 54 | this.RootElement = xDoc.Root; 55 | } 56 | 57 | public XElement RootElement { get; set; } 58 | 59 | public void LoadConfiguration(DataConnectionDialog dialog) 60 | { 61 | dialog.DataSources.Add(DataSource.SqlDataSource); 62 | dialog.DataSources.Add(DataSource.SqlFileDataSource); 63 | dialog.DataSources.Add(DataSource.OracleDataSource); 64 | dialog.DataSources.Add(DataSource.AccessDataSource); 65 | dialog.DataSources.Add(DataSource.OdbcDataSource); 66 | dialog.DataSources.Add(SqlCe.SqlCeDataSource); 67 | 68 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.SqlDataProvider); 69 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.OracleDataProvider); 70 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.OleDBDataProvider); 71 | dialog.UnspecifiedDataSource.Providers.Add(DataProvider.OdbcDataProvider); 72 | dialog.DataSources.Add(dialog.UnspecifiedDataSource); 73 | 74 | this.dataSources = new Dictionary(); 75 | this.dataSources.Add(DataSource.SqlDataSource.Name, DataSource.SqlDataSource); 76 | this.dataSources.Add(DataSource.SqlFileDataSource.Name, DataSource.SqlFileDataSource); 77 | this.dataSources.Add(DataSource.OracleDataSource.Name, DataSource.OracleDataSource); 78 | this.dataSources.Add(DataSource.AccessDataSource.Name, DataSource.AccessDataSource); 79 | this.dataSources.Add(DataSource.OdbcDataSource.Name, DataSource.OdbcDataSource); 80 | this.dataSources.Add(SqlCe.SqlCeDataSource.Name, SqlCe.SqlCeDataSource); 81 | this.dataSources.Add(dialog.UnspecifiedDataSource.DisplayName, dialog.UnspecifiedDataSource); 82 | 83 | this.dataProviders = new Dictionary(); 84 | this.dataProviders.Add(DataProvider.SqlDataProvider.Name, DataProvider.SqlDataProvider); 85 | this.dataProviders.Add(DataProvider.OracleDataProvider.Name, DataProvider.OracleDataProvider); 86 | this.dataProviders.Add(DataProvider.OleDBDataProvider.Name, DataProvider.OleDBDataProvider); 87 | this.dataProviders.Add(DataProvider.OdbcDataProvider.Name, DataProvider.OdbcDataProvider); 88 | this.dataProviders.Add(SqlCe.SqlCeDataProvider.Name, SqlCe.SqlCeDataProvider); 89 | 90 | 91 | DataSource ds = null; 92 | string dsName = this.GetSelectedSource(); 93 | if (!String.IsNullOrEmpty(dsName) && this.dataSources.TryGetValue(dsName, out ds)) 94 | { 95 | dialog.SelectedDataSource = ds; 96 | } 97 | 98 | DataProvider dp = null; 99 | string dpName = this.GetSelectedProvider(); 100 | if (!String.IsNullOrEmpty(dpName) && this.dataProviders.TryGetValue(dpName, out dp)) 101 | { 102 | dialog.SelectedDataProvider = dp; 103 | } 104 | } 105 | 106 | public void SaveConfiguration(DataConnectionDialog dcd) 107 | { 108 | if (dcd.SaveSelection) 109 | { 110 | DataSource ds = dcd.SelectedDataSource; 111 | if (ds != null) 112 | { 113 | if (ds == dcd.UnspecifiedDataSource) 114 | { 115 | this.SaveSelectedSource(ds.DisplayName); 116 | } 117 | else 118 | { 119 | this.SaveSelectedSource(ds.Name); 120 | } 121 | } 122 | DataProvider dp = dcd.SelectedDataProvider; 123 | if (dp != null) 124 | { 125 | this.SaveSelectedProvider(dp.Name); 126 | } 127 | 128 | xDoc.Save(fullFilePath); 129 | } 130 | } 131 | 132 | public string GetSelectedSource() 133 | { 134 | try 135 | { 136 | XElement xElem = this.RootElement.Element("DataSourceSelection"); 137 | XElement sourceElem = xElem.Element("SelectedSource"); 138 | if (sourceElem != null) 139 | { 140 | return sourceElem.Value as string; 141 | } 142 | } 143 | catch 144 | { 145 | return null; 146 | } 147 | return null; 148 | } 149 | 150 | public string GetSelectedProvider() 151 | { 152 | try 153 | { 154 | XElement xElem = this.RootElement.Element("DataSourceSelection"); 155 | XElement providerElem = xElem.Element("SelectedProvider"); 156 | if (providerElem != null) 157 | { 158 | return providerElem.Value as string; 159 | } 160 | } 161 | catch 162 | { 163 | return null; 164 | } 165 | return null; 166 | } 167 | 168 | public void SaveSelectedSource(string source) 169 | { 170 | if (!String.IsNullOrEmpty(source)) 171 | { 172 | try 173 | { 174 | XElement xElem = this.RootElement.Element("DataSourceSelection"); 175 | XElement sourceElem = xElem.Element("SelectedSource"); 176 | if (sourceElem != null) 177 | { 178 | sourceElem.Value = source; 179 | } 180 | else 181 | { 182 | xElem.Add(new XElement("SelectedSource", source)); 183 | } 184 | } 185 | catch 186 | { 187 | } 188 | } 189 | 190 | } 191 | 192 | public void SaveSelectedProvider(string provider) 193 | { 194 | if (!String.IsNullOrEmpty(provider)) 195 | { 196 | try 197 | { 198 | XElement xElem = this.RootElement.Element("DataSourceSelection"); 199 | XElement sourceElem = xElem.Element("SelectedProvider"); 200 | if (sourceElem != null) 201 | { 202 | sourceElem.Value = provider; 203 | } 204 | else 205 | { 206 | xElem.Add(new XElement("SelectedProvider", provider)); 207 | } 208 | } 209 | catch 210 | { 211 | } 212 | } 213 | } 214 | } 215 | } 216 | -------------------------------------------------------------------------------- /Source/Sample/IDataConnectionConfiguration.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Text; 10 | 11 | namespace Microsoft.Data.ConnectionUI 12 | { 13 | public interface IDataConnectionConfiguration 14 | { 15 | string GetSelectedSource(); 16 | void SaveSelectedSource(string provider); 17 | 18 | string GetSelectedProvider(); 19 | void SaveSelectedProvider(string provider); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Source/Sample/Microsoft.Data.ConnectionUI.Sample.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {444AC953-5861-49CA-B491-9EB8A1C6CE24} 9 | Exe 10 | Properties 11 | Microsoft.Data.ConnectionUI 12 | Microsoft.Data.ConnectionUI.Sample 13 | v4.5.2 14 | 512 15 | publish\ 16 | true 17 | Disk 18 | false 19 | Foreground 20 | 7 21 | Days 22 | false 23 | false 24 | true 25 | 0 26 | 1.0.0.%2a 27 | false 28 | false 29 | true 30 | 31 | 32 | 33 | 34 | 3.5 35 | 36 | 37 | 38 | true 39 | full 40 | false 41 | bin\Debug\ 42 | DEBUG;TRACE 43 | prompt 44 | 4 45 | false 46 | x86 47 | false 48 | 49 | 50 | pdbonly 51 | true 52 | bin\Release\ 53 | TRACE 54 | prompt 55 | 4 56 | false 57 | 58 | 59 | true 60 | bin\x86\Debug\ 61 | DEBUG;TRACE 62 | full 63 | x86 64 | true 65 | GlobalSuppressions.cs 66 | false 67 | prompt 68 | false 69 | 70 | 71 | bin\x86\Release\ 72 | TRACE 73 | true 74 | pdbonly 75 | x86 76 | true 77 | GlobalSuppressions.cs 78 | prompt 79 | false 80 | 81 | 82 | true 83 | bin\x64\Debug\ 84 | DEBUG;TRACE 85 | full 86 | x64 87 | true 88 | GlobalSuppressions.cs 89 | false 90 | prompt 91 | false 92 | 93 | 94 | bin\x64\Release\ 95 | TRACE 96 | true 97 | pdbonly 98 | x64 99 | true 100 | GlobalSuppressions.cs 101 | prompt 102 | false 103 | 104 | 105 | app.manifest 106 | 107 | 108 | 109 | 110 | 3.5 111 | 112 | 113 | 114 | 3.5 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA} 128 | Microsoft.Data.ConnectionUI.Dialog 129 | 130 | 131 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31} 132 | Microsoft.Data.ConnectionUI.SqlCeDataProvider 133 | 134 | 135 | 136 | 137 | False 138 | .NET Framework Client Profile 139 | false 140 | 141 | 142 | False 143 | .NET Framework 2.0 %28x86%29 144 | false 145 | 146 | 147 | False 148 | .NET Framework 3.0 %28x86%29 149 | false 150 | 151 | 152 | False 153 | .NET Framework 3.5 154 | false 155 | 156 | 157 | False 158 | .NET Framework 3.5 SP1 159 | true 160 | 161 | 162 | False 163 | Windows Installer 3.1 164 | true 165 | 166 | 167 | 168 | 169 | 170 | Designer 171 | 172 | 173 | 174 | 181 | -------------------------------------------------------------------------------- /Source/Sample/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Sample")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("Sample")] 13 | [assembly: AssemblyCopyright("Copyright © 2009")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("981748b1-8769-42a1-9e01-97b40a887662")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Source/Sample/Sample.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Data.SqlClient; 10 | using System.Linq; 11 | using System.Text; 12 | using System.Windows.Forms; 13 | 14 | using Microsoft.Data.ConnectionUI; 15 | using System.Data.Common; 16 | using System.Data; 17 | 18 | namespace Sample 19 | { 20 | public class Sample 21 | { 22 | // Sample 1: 23 | [STAThread] 24 | static void Main(string[] args) 25 | { 26 | DataConnectionDialog dcd = new DataConnectionDialog(); 27 | DataConnectionConfiguration dcs = new DataConnectionConfiguration(null); 28 | dcs.LoadConfiguration(dcd); 29 | 30 | if (DataConnectionDialog.Show(dcd) == DialogResult.OK) 31 | { 32 | DbProviderFactory factory = DbProviderFactories.GetFactory(dcd.SelectedDataProvider.Name); 33 | using (var connection = factory.CreateConnection()) 34 | { 35 | connection.ConnectionString = dcd.ConnectionString; 36 | connection.Open(); 37 | var command = connection.CreateCommand(); 38 | command.CommandType = CommandType.Text; 39 | command.CommandText = "SELECT * FROM INFORMATION_SCHEMA.TABLES"; 40 | using (var reader = command.ExecuteReader()) 41 | { 42 | while (reader.Read()) 43 | { 44 | Console.WriteLine(reader["name"]); 45 | } 46 | } 47 | } 48 | 49 | // load tables 50 | //using (SqlConnection connection = new SqlConnection(dcd.ConnectionString)) 51 | //{ 52 | // connection.Open(); 53 | // SqlCommand cmd = new SqlCommand("SELECT * FROM sys.Tables", connection); 54 | 55 | // using (SqlDataReader reader = cmd.ExecuteReader()) 56 | // { 57 | // while (reader.Read()) 58 | // { 59 | // Console.WriteLine(reader.HasRows); 60 | // } 61 | // } 62 | 63 | //} 64 | } 65 | 66 | dcs.SaveConfiguration(dcd); 67 | } 68 | 69 | // Sample 2: 70 | //[STAThread] 71 | //static void Main(string[] args) 72 | //{ 73 | // DataConnectionDialog dcd = new DataConnectionDialog(); 74 | // DataConnectionConfiguration dcs = new DataConnectionConfiguration(null); 75 | // dcs.LoadConfiguration(dcd); 76 | // //dcd.ConnectionString = "Data Source=ziz-vspro-sql05;Initial Catalog=Northwind;Persist Security Info=True;User ID=sa;Password=Admin_007"; 77 | 78 | 79 | // if (DataConnectionDialog.Show(dcd) == DialogResult.OK) 80 | // { 81 | // // load tables 82 | // using (SqlConnection connection = new SqlConnection(dcd.ConnectionString)) 83 | // { 84 | // connection.Open(); 85 | // SqlCommand cmd = new SqlCommand("SELECT * FROM sys.Tables", connection); 86 | 87 | // using (SqlDataReader reader = cmd.ExecuteReader()) 88 | // { 89 | // while (reader.Read()) 90 | // { 91 | // Console.WriteLine(reader.HasRows); 92 | // } 93 | // } 94 | 95 | // } 96 | // } 97 | 98 | // dcs.SaveConfiguration(dcd); 99 | //} 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /Source/Sample/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /Source/Sample/app.manifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 55 | 56 | 57 | 58 | 59 | false 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /Source/SqlCeDataProvider/Microsoft.Data.ConnectionUI.SqlCeDataProvider.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {1CC9D080-C06D-4202-A14B-14A9CC7F7F31} 9 | Library 10 | Properties 11 | Microsoft.Data.ConnectionUI 12 | Microsoft.Data.ConnectionUI.SqlCeDataProvider 13 | v3.5 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | true 23 | full 24 | false 25 | bin\Debug\ 26 | DEBUG;TRACE 27 | prompt 28 | 4 29 | 30 | 31 | pdbonly 32 | true 33 | bin\Release\ 34 | TRACE 35 | prompt 36 | 4 37 | 38 | 39 | true 40 | bin\x86\Debug\ 41 | DEBUG;TRACE 42 | full 43 | x86 44 | true 45 | GlobalSuppressions.cs 46 | prompt 47 | 48 | 49 | bin\x86\Release\ 50 | TRACE 51 | true 52 | pdbonly 53 | x86 54 | true 55 | GlobalSuppressions.cs 56 | prompt 57 | 58 | 59 | true 60 | bin\x64\Debug\ 61 | DEBUG;TRACE 62 | full 63 | x64 64 | true 65 | GlobalSuppressions.cs 66 | prompt 67 | 68 | 69 | bin\x64\Release\ 70 | TRACE 71 | true 72 | pdbonly 73 | x64 74 | true 75 | GlobalSuppressions.cs 76 | prompt 77 | 78 | 79 | 80 | False 81 | ..\References\Microsoft.SqlServerCe.Client.dll 82 | 83 | 84 | 85 | 3.5 86 | 87 | 88 | 89 | 90 | 91 | 3.5 92 | 93 | 94 | 3.5 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | True 103 | True 104 | Resources.resx 105 | 106 | 107 | 108 | 109 | UserControl 110 | 111 | 112 | SqlCeConnectionUIControl.cs 113 | 114 | 115 | 116 | 117 | ResXFileCodeGenerator 118 | Resources.Designer.cs 119 | Designer 120 | 121 | 122 | SqlCeConnectionUIControl.cs 123 | 124 | 125 | 126 | 127 | {05C97F8D-B7CF-4CAB-B81C-0994A70D90CA} 128 | Microsoft.Data.ConnectionUI.Dialog 129 | 130 | 131 | {139729CD-0F06-48E8-9F4A-08E78BB6575F} 132 | Microsoft.Data.ConnectionUI 133 | 134 | 135 | 136 | 143 | -------------------------------------------------------------------------------- /Source/SqlCeDataProvider/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Microsoft.Data.ConnectionUI.SqlCeDataProvider")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("Microsoft.Data.ConnectionUI.SqlCeDataProvider")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2009")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("f364c296-49db-488b-889b-1a4dd8efca1b")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Source/SqlCeDataProvider/SqlCeConnection.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Text; 11 | 12 | namespace Microsoft.Data.ConnectionUI 13 | { 14 | public class SqlCe 15 | { 16 | public static DataSource SqlCeDataSource 17 | { 18 | get 19 | { 20 | if (_sqlCeDataSource == null) 21 | { 22 | _sqlCeDataSource = new DataSource("SqlCeClient", "Microsoft SQL Server Compact 3.5"); 23 | _sqlCeDataSource.Providers.Add(SqlCeDataProvider); 24 | } 25 | return _sqlCeDataSource; 26 | } 27 | } 28 | 29 | private static DataSource _sqlCeDataSource; 30 | 31 | public static DataProvider SqlCeDataProvider 32 | { 33 | get 34 | { 35 | if (_sqlCeDataProvider == null) 36 | { 37 | Dictionary descriptions = new Dictionary(); 38 | descriptions.Add(SqlCeDataSource.Name, Resources.DataProvider_SqlEverywhere_Description); 39 | 40 | Dictionary uiControls = new Dictionary(); 41 | uiControls.Add(String.Empty, typeof(SqlCeConnectionUIControl)); 42 | 43 | _sqlCeDataProvider = new DataProvider( 44 | "System.Data.SqlCeClient", 45 | Resources.DataProvider_SqlEverywhere, 46 | "SqlCeClient", 47 | Resources.DataProvider_SqlEverywhere_Description, 48 | typeof(System.Data.SqlServerCe.SqlCeConnection), 49 | descriptions, 50 | uiControls, 51 | typeof(SqlCeConnectionProperties)); 52 | } 53 | return _sqlCeDataProvider; 54 | } 55 | } 56 | private static DataProvider _sqlCeDataProvider; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Source/SqlCeDataProvider/SqlCeConnectionProperties.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.IO; 9 | using System.ComponentModel; 10 | using System.Drawing.Design; 11 | using System.Collections.Specialized; 12 | using System.Windows.Forms; 13 | using Microsoft.SqlServerCe.Client; 14 | 15 | namespace Microsoft.Data.ConnectionUI 16 | { 17 | 18 | public class SqlCeConnectionProperties : AdoDotNetConnectionProperties 19 | { 20 | public SqlCeConnectionProperties() 21 | : base("System.Data.SqlClient") 22 | { 23 | } 24 | 25 | public override void Reset() 26 | { 27 | base.Reset(); 28 | } 29 | 30 | public override bool IsComplete 31 | { 32 | get 33 | { 34 | 35 | string dataSource = this["Data Source"] as string; 36 | 37 | if (String.IsNullOrEmpty(dataSource)) 38 | { 39 | return false; 40 | } 41 | 42 | // Ensure file extension: 43 | if (!(Path.GetExtension(dataSource).Equals(".sdf", StringComparison.OrdinalIgnoreCase))) 44 | { 45 | return false; 46 | } 47 | 48 | return true; 49 | } 50 | } 51 | 52 | protected override string ToTestString() 53 | { 54 | bool savedPooling = (bool)ConnectionStringBuilder["Pooling"]; 55 | bool wasDefault = !ConnectionStringBuilder.ShouldSerialize("Pooling"); 56 | ConnectionStringBuilder["Pooling"] = false; 57 | string testString = ConnectionStringBuilder.ConnectionString; 58 | ConnectionStringBuilder["Pooling"] = savedPooling; 59 | if (wasDefault) 60 | { 61 | ConnectionStringBuilder.Remove("Pooling"); 62 | } 63 | return testString; 64 | } 65 | 66 | public override void Test() 67 | { 68 | string testString = ToTestString(); 69 | 70 | 71 | // Create a connection object 72 | SqlCeConnection connection = new SqlCeConnection(); 73 | 74 | // Try to open it 75 | try 76 | { 77 | connection.ConnectionString = ToFullString(); 78 | connection.Open(); 79 | } 80 | catch (SqlCeException e) 81 | { 82 | // Customize the error message for upgrade required 83 | if (e.Number == m_intDatabaseFileNeedsUpgrading) 84 | { 85 | throw new InvalidOperationException(Resources.SqlCeConnectionProperties_FileNeedsUpgrading); 86 | } 87 | throw; 88 | } 89 | finally 90 | { 91 | connection.Dispose(); 92 | } 93 | } 94 | 95 | private const int m_intDatabaseFileNeedsUpgrading = 25138; 96 | 97 | } 98 | } 99 | 100 | -------------------------------------------------------------------------------- /Source/SqlCeDataProvider/SqlCeConnectionUIControl.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Microsoft.Data.ConnectionUI 2 | { 3 | partial class SqlCeConnectionUIControl 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Component Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SqlCeConnectionUIControl)); 32 | this.dataSourceGroupBox = new System.Windows.Forms.GroupBox(); 33 | this.activeSyncRadioButton = new System.Windows.Forms.RadioButton(); 34 | this.myComputerRadioButton = new System.Windows.Forms.RadioButton(); 35 | this.propertiesGroupBox = new System.Windows.Forms.GroupBox(); 36 | this.savePasswordCheckBox = new System.Windows.Forms.CheckBox(); 37 | this.databaseButtonsTableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 38 | this.browseButton = new System.Windows.Forms.Button(); 39 | this.createButton = new System.Windows.Forms.Button(); 40 | this.passwordTextBox = new System.Windows.Forms.TextBox(); 41 | this.databaseTextBox = new System.Windows.Forms.TextBox(); 42 | this.passwordLabel = new System.Windows.Forms.Label(); 43 | this.databaseLabel = new System.Windows.Forms.Label(); 44 | this.dataSourceGroupBox.SuspendLayout(); 45 | this.propertiesGroupBox.SuspendLayout(); 46 | this.databaseButtonsTableLayoutPanel.SuspendLayout(); 47 | this.SuspendLayout(); 48 | // 49 | // dataSourceGroupBox 50 | // 51 | resources.ApplyResources(this.dataSourceGroupBox, "dataSourceGroupBox"); 52 | this.dataSourceGroupBox.Controls.Add(this.activeSyncRadioButton); 53 | this.dataSourceGroupBox.Controls.Add(this.myComputerRadioButton); 54 | this.dataSourceGroupBox.FlatStyle = System.Windows.Forms.FlatStyle.System; 55 | this.dataSourceGroupBox.Name = "dataSourceGroupBox"; 56 | this.dataSourceGroupBox.TabStop = false; 57 | // 58 | // activeSyncRadioButton 59 | // 60 | resources.ApplyResources(this.activeSyncRadioButton, "activeSyncRadioButton"); 61 | this.activeSyncRadioButton.Name = "activeSyncRadioButton"; 62 | this.activeSyncRadioButton.TabStop = true; 63 | this.activeSyncRadioButton.UseVisualStyleBackColor = true; 64 | this.activeSyncRadioButton.CheckedChanged += new System.EventHandler(this.activeSyncRadioButton_CheckedChanged); 65 | // 66 | // myComputerRadioButton 67 | // 68 | resources.ApplyResources(this.myComputerRadioButton, "myComputerRadioButton"); 69 | this.myComputerRadioButton.Name = "myComputerRadioButton"; 70 | this.myComputerRadioButton.TabStop = true; 71 | this.myComputerRadioButton.UseVisualStyleBackColor = true; 72 | this.myComputerRadioButton.CheckedChanged += new System.EventHandler(this.myComputerRadioButton_CheckedChanged); 73 | // 74 | // propertiesGroupBox 75 | // 76 | resources.ApplyResources(this.propertiesGroupBox, "propertiesGroupBox"); 77 | this.propertiesGroupBox.Controls.Add(this.savePasswordCheckBox); 78 | this.propertiesGroupBox.Controls.Add(this.databaseButtonsTableLayoutPanel); 79 | this.propertiesGroupBox.Controls.Add(this.passwordTextBox); 80 | this.propertiesGroupBox.Controls.Add(this.databaseTextBox); 81 | this.propertiesGroupBox.Controls.Add(this.passwordLabel); 82 | this.propertiesGroupBox.Controls.Add(this.databaseLabel); 83 | this.propertiesGroupBox.FlatStyle = System.Windows.Forms.FlatStyle.System; 84 | this.propertiesGroupBox.Name = "propertiesGroupBox"; 85 | this.propertiesGroupBox.TabStop = false; 86 | // 87 | // savePasswordCheckBox 88 | // 89 | resources.ApplyResources(this.savePasswordCheckBox, "savePasswordCheckBox"); 90 | this.savePasswordCheckBox.Name = "savePasswordCheckBox"; 91 | this.savePasswordCheckBox.UseVisualStyleBackColor = true; 92 | this.savePasswordCheckBox.CheckedChanged += new System.EventHandler(this.savePasswordCheckBox_CheckedChanged); 93 | // 94 | // databaseButtonsTableLayoutPanel 95 | // 96 | resources.ApplyResources(this.databaseButtonsTableLayoutPanel, "databaseButtonsTableLayoutPanel"); 97 | this.databaseButtonsTableLayoutPanel.Controls.Add(this.browseButton, 1, 0); 98 | this.databaseButtonsTableLayoutPanel.Controls.Add(this.createButton, 0, 0); 99 | this.databaseButtonsTableLayoutPanel.Name = "databaseButtonsTableLayoutPanel"; 100 | // 101 | // browseButton 102 | // 103 | resources.ApplyResources(this.browseButton, "browseButton"); 104 | this.browseButton.MinimumSize = new System.Drawing.Size(75, 23); 105 | this.browseButton.Name = "browseButton"; 106 | this.browseButton.UseVisualStyleBackColor = true; 107 | this.browseButton.Click += new System.EventHandler(this.browseButton_Click); 108 | // 109 | // createButton 110 | // 111 | resources.ApplyResources(this.createButton, "createButton"); 112 | this.createButton.MinimumSize = new System.Drawing.Size(75, 23); 113 | this.createButton.Name = "createButton"; 114 | this.createButton.UseVisualStyleBackColor = true; 115 | // 116 | // passwordTextBox 117 | // 118 | resources.ApplyResources(this.passwordTextBox, "passwordTextBox"); 119 | this.passwordTextBox.Name = "passwordTextBox"; 120 | this.passwordTextBox.UseSystemPasswordChar = true; 121 | this.passwordTextBox.TextChanged += new System.EventHandler(this.passwordTextBox_TextChanged); 122 | // 123 | // databaseTextBox 124 | // 125 | resources.ApplyResources(this.databaseTextBox, "databaseTextBox"); 126 | this.databaseTextBox.Name = "databaseTextBox"; 127 | this.databaseTextBox.Leave += new System.EventHandler(this.TrimControlText); 128 | this.databaseTextBox.TextChanged += new System.EventHandler(this.databaseTextBox_TextChanged); 129 | // 130 | // passwordLabel 131 | // 132 | resources.ApplyResources(this.passwordLabel, "passwordLabel"); 133 | this.passwordLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 134 | this.passwordLabel.Name = "passwordLabel"; 135 | // 136 | // databaseLabel 137 | // 138 | resources.ApplyResources(this.databaseLabel, "databaseLabel"); 139 | this.databaseLabel.FlatStyle = System.Windows.Forms.FlatStyle.System; 140 | this.databaseLabel.Name = "databaseLabel"; 141 | // 142 | // SqlCeConnectionUIControl 143 | // 144 | resources.ApplyResources(this, "$this"); 145 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 146 | this.Controls.Add(this.propertiesGroupBox); 147 | this.Controls.Add(this.dataSourceGroupBox); 148 | this.MinimumSize = new System.Drawing.Size(300, 247); 149 | this.Name = "SqlCeConnectionUIControl"; 150 | this.dataSourceGroupBox.ResumeLayout(false); 151 | this.dataSourceGroupBox.PerformLayout(); 152 | this.propertiesGroupBox.ResumeLayout(false); 153 | this.propertiesGroupBox.PerformLayout(); 154 | this.databaseButtonsTableLayoutPanel.ResumeLayout(false); 155 | this.databaseButtonsTableLayoutPanel.PerformLayout(); 156 | this.ResumeLayout(false); 157 | 158 | } 159 | 160 | #endregion 161 | 162 | private System.Windows.Forms.GroupBox dataSourceGroupBox; 163 | private System.Windows.Forms.RadioButton myComputerRadioButton; 164 | private System.Windows.Forms.RadioButton activeSyncRadioButton; 165 | private System.Windows.Forms.GroupBox propertiesGroupBox; 166 | private System.Windows.Forms.Label databaseLabel; 167 | private System.Windows.Forms.Label passwordLabel; 168 | private System.Windows.Forms.TextBox databaseTextBox; 169 | private System.Windows.Forms.TextBox passwordTextBox; 170 | private System.Windows.Forms.TableLayoutPanel databaseButtonsTableLayoutPanel; 171 | private System.Windows.Forms.Button browseButton; 172 | private System.Windows.Forms.Button createButton; 173 | private System.Windows.Forms.CheckBox savePasswordCheckBox; 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /Source/SqlCeDataProvider/SqlCeConnectionUIControl.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // Copyright (c) Microsoft Corporation. All rights reserved. 4 | // 5 | //------------------------------------------------------------------------------ 6 | 7 | using System; 8 | using System.Diagnostics; 9 | using System.IO; 10 | using System.Windows.Forms; 11 | 12 | using Microsoft.Data.ConnectionUI; 13 | using Microsoft.SqlServerCe.Client; 14 | using Microsoft.Win32; 15 | 16 | 17 | namespace Microsoft.Data.ConnectionUI 18 | { 19 | /// 20 | /// Represents the connection UI control for the SQL Server Compact provider. 21 | /// 22 | internal partial class SqlCeConnectionUIControl : UserControl, IDataConnectionUIControl 23 | { 24 | private bool _loading; 25 | 26 | private SqlCeConnectionProperties _properties; 27 | 28 | public SqlCeConnectionUIControl() 29 | { 30 | InitializeComponent(); 31 | RightToLeft = RightToLeft.Inherit; 32 | 33 | // Disable the active sync radio button for standalone connection dialog. 34 | this.activeSyncRadioButton.Enabled = false; 35 | this.createButton.Enabled = false; 36 | } 37 | 38 | private string DataSourceProperty 39 | { 40 | get 41 | { 42 | return "Data Source"; 43 | } 44 | } 45 | 46 | public static string MobileDevicePrefix 47 | { 48 | get 49 | { 50 | return ConStringUtil.MobileDevicePrefix + @"\"; 51 | } 52 | } 53 | 54 | private string PasswordProperty 55 | { 56 | get 57 | { 58 | return "Password"; 59 | } 60 | } 61 | 62 | 63 | public string PersistSecurityInfoProperty 64 | { 65 | get 66 | { 67 | return "Persist Security Info"; 68 | } 69 | } 70 | 71 | 72 | public void Initialize(IDataConnectionProperties connectionProperties) 73 | { 74 | if (connectionProperties == null) 75 | { 76 | throw new ArgumentNullException("connectionProperties"); 77 | } 78 | SqlCeConnectionProperties properties = connectionProperties as SqlCeConnectionProperties; 79 | if (properties == null) 80 | { 81 | throw new ArgumentException(Resources.SqlCeConnectionUIControl_InvalidConnectionProperties); 82 | } 83 | _properties = properties; 84 | } 85 | 86 | public void LoadProperties() 87 | { 88 | _loading = true; 89 | 90 | string dataSource = _properties[DataSourceProperty] as string; 91 | myComputerRadioButton.Checked = true; 92 | databaseTextBox.Text = dataSource; 93 | passwordTextBox.Text = _properties[PasswordProperty] as string; 94 | savePasswordCheckBox.Checked = (bool)_properties[PersistSecurityInfoProperty]; 95 | 96 | _loading = false; 97 | } 98 | 99 | 100 | private void myComputerRadioButton_CheckedChanged(object sender, EventArgs e) 101 | { 102 | databaseTextBox_TextChanged(sender, e); 103 | } 104 | 105 | private void activeSyncRadioButton_CheckedChanged(object sender, EventArgs e) 106 | { 107 | databaseTextBox_TextChanged(sender, e); 108 | } 109 | 110 | private void databaseTextBox_TextChanged(object sender, EventArgs e) 111 | { 112 | if (!_loading) 113 | { 114 | string dataSource = databaseTextBox.Text.Trim(); 115 | if (activeSyncRadioButton.Checked) 116 | { 117 | dataSource = Path.Combine(MobileDevicePrefix, dataSource); 118 | } 119 | if (dataSource.Length == 0) 120 | { 121 | dataSource = null; 122 | } 123 | _properties[DataSourceProperty] = dataSource; 124 | } 125 | } 126 | 127 | private void browseButton_Click(object sender, EventArgs e) 128 | { 129 | if (myComputerRadioButton.Checked) 130 | { 131 | // 132 | // We're exploring the desktop, let's use an OpenFileDialog 133 | // 134 | using (OpenFileDialog fileDialog = new OpenFileDialog()) 135 | { 136 | fileDialog.Title = Resources.SqlConnectionUIControl_BrowseFileTitle; 137 | fileDialog.Multiselect = false; 138 | if (String.IsNullOrEmpty(_properties[DataSourceProperty] as string)) 139 | { 140 | fileDialog.InitialDirectory = InitialDirectory; 141 | } 142 | fileDialog.RestoreDirectory = true; 143 | fileDialog.Filter = Resources.SqlConnectionUIControl_BrowseFileFilter; 144 | fileDialog.DefaultExt = Resources.SqlConnectionUIControl_BrowseFileDefaultExt; 145 | if (fileDialog.ShowDialog() == DialogResult.OK) 146 | { 147 | _properties[DataSourceProperty] = fileDialog.FileName.Trim(); 148 | LoadProperties(); 149 | } 150 | } 151 | } 152 | } 153 | 154 | private void passwordTextBox_TextChanged(object sender, EventArgs e) 155 | { 156 | if (!_loading) 157 | { 158 | _properties[PasswordProperty] = (passwordTextBox.Text.Length > 0) ? passwordTextBox.Text : null; 159 | passwordTextBox.Text = passwordTextBox.Text; // forces reselection of all text 160 | } 161 | } 162 | 163 | private void savePasswordCheckBox_CheckedChanged(object sender, EventArgs e) 164 | { 165 | if (!_loading) 166 | { 167 | _properties[PersistSecurityInfoProperty] = savePasswordCheckBox.Checked; 168 | } 169 | } 170 | 171 | private void TrimControlText(object sender, EventArgs e) 172 | { 173 | Control c = sender as Control; 174 | c.Text = c.Text.Trim(); 175 | } 176 | 177 | private static string InitialDirectory 178 | { 179 | get 180 | { 181 | string path = null; 182 | RegistryKey sqlCEBaseRegKey = Registry.LocalMachine.OpenSubKey( 183 | @"SOFTWARE\Microsoft\Microsoft SQL Server Compact Edition\v3.5"); 184 | if (sqlCEBaseRegKey != null) 185 | { 186 | using (sqlCEBaseRegKey) 187 | { 188 | path = sqlCEBaseRegKey.GetValue("InstallDir") as string; 189 | if (path != null) 190 | { 191 | path = Path.Combine(path, "Samples"); 192 | } 193 | } 194 | } 195 | return path; 196 | } 197 | } 198 | 199 | } 200 | } 201 | --------------------------------------------------------------------------------