Shawn Wildermuth

Author, Teacher, and Filmmaker
.NET Foundation Board Member

Using the Visual Studio Connection String Dialog

Using the Visual Studio Connection String Dialog


Chris Sells asked me today if there was a re-usable connection string user interface that I knew of.  I'd heard that you could use the dialog from Visual Studio, but I had to dig in and remember how.  I've put together this quick and dirty example for downloading.

The trick is two fold:

  • You need to add Microsoft.Data.ConnectionUI.dll and MicrosoftData.ConnectionUI.Dialog.dll assemblies to your project.  (they are found i the VS2005/Common7/IDE directory)
  • Next you need to construct the dialog like any other, but first fill it with the standard providers as well as use the static Show method:


DataConnectionDialog dlg = new DataConnectionDialog();
if (DataConnectionDialog.Show(dlg) == DialogResult.OK)
  textBox1.Text = dlg.ConnectionString;
  textBox2.Text = dlg.SelectedDataProvider.DisplayName;

The sample includes how to find out if the user wants to save the provider and skip that part of the dialog everytime.  Let me kow what you think!