Call vs Data source Implementation database connection string configuration

Source: Internet
Author: User
Data | database | database connection | data Source | string

We often provide an interface between the optional data source and the data connection configuration in the development application to facilitate the user to configure the database connection string. A typical approach is to write this information in a configuration file, such as a Web.config or app.config file.

But the customer is not a professional programmer, accidentally will make the connection string error, resulting in the system can not run, the best is to enable users to select a graphical interface to the data source and data connection information, the following figure:

We can simply implement this by invoking the database connection configuration UI in Visual Studio.

The specific implementation methods are as follows:

First, add a reference to Microsoft.Data.ConnectionUI.Dialog.dll, which is under the VS2005 installation directory, C:\Program Files\Microsoft Visual Studio 8\ Common7\IDE below, my vs is installed in C disk, here is the code:

Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Text;
Using System.Windows.Forms;

Using Microsoft.Data.ConnectionUI;

Namespace Connectionbuilder
{
public partial class Connectionform:form
{
Public Connectionform ()
{
InitializeComponent ();
}

private void Btncreateconnection (object sender, EventArgs e)
{
Dataconnectiondialog dialog = new Dataconnectiondialog ();

Add a list of data sources to add to the window the type of data source you need for your program
Dialog. Datasources.add (Datasource.sqldatasource);
Dialog. Datasources.add (Datasource.odbcdatasource);

Dialog. Selecteddatasource = Datasource.odbcdatasource;
Dialog. Selecteddataprovider = Dataprovider.odbcdataprovider;

Can show dialog box only through static method of Dataconnectiondialog class
Different use of dialog. Show () or dialog. ShowDialog () To render the dialog box
if (dataconnectiondialog.show (dialog, this) = = DialogResult.OK)
{
Txtconnectionstring.text = dialog. ConnectionString;
}
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.