Introduction
Quite often, a programmer working with a relational database has a problem how to make the connection setup convenient for the end user. Someone stores the connection string directly in NameApp.exe.config, this is of course inconvenient, since in order to change the connection, you have to edit the file with your hands. Most developers write their own classes and create forms for editing the connection string directly in the application. This is a good way, if you have already spent your time on it, but if you start from scratch, you hardly want to spend several hours creating a connection dialog box.
I work in VS2010 and I like the studio connection window, it looks like this (hereinafter, we will discuss the SQL Server Data Provider):

Why not use this form in your applications?
The main advantage of this dialogue form is that it is possible to choose a SQL Server available on the network and a database that corresponds to the server.
')
Getting started
A little search, it turns out that we are interested in Microsoft Data Connection Dialog
(who would have thought?) . Great, spend another five minutes and in the msdn archives we find the
source code and documentation for the project. This could have been the end of the article, because the documentation describes everything very well and affordably, but let's continue.
We connect
We create a new project, specify the target platform .NET Framework 4.0 (Client Profie
will not work! ), Throw the button and the textbox on the form.

Next, we add two DataConnectionConfiguration.cs and IDataConnectionConfiguration.cs files from the ... ConnectionDialog \ Sample \ project with msdn to our project. In the first - the class that implements the list of data providers and saving the selected (saves in xml), the second - respectively, the interface class. You also need two libraries: Microsoft.Data.ConnectionUI and Microsoft.Data.ConnectionUI.Dialog, you can take them from the folder ... ConnectionDialog \ ConnectionDialogUI \ bin \ Debug (Release) \, having previously built the project. This is what should happen:

We use
Now go to the code. In order to use the dialog box, you must initialize the DataConnectionDialog class and get the connection to the database from the ConnectionString property.
Let's write a simple function that brings up a dialog box and, when you click the OK button, returns a connection string:
private string GetConnectionString() { string connectionString = null; DataConnectionDialog dcd = new DataConnectionDialog(); DataConnectionConfiguration dcs = new DataConnectionConfiguration(null); dcs.LoadConfiguration(dcd); if (DataConnectionDialog.Show(dcd) == DialogResult.OK) connectionString = dcd.ConnectionString; dcs.SaveConfiguration(dcd); return connectionString; }
Now use this function in the button1 handler.
private void button1_Click(object sender, EventArgs e) { textBox1.Text = GetConnectionString(); }
We start the project, press the button, select the supplier, specify the server and database, click OK and see the connection string to the database in the textbox.

Conclusion
The only drawback is that you will not see the great and mighty in the dialog box. For this, you will have to manually localize the forms and the Strings.resx file in the ConnectionUIDialog project. You can take the project localized by me
here (project VS2010 SP1).