WinForm Program Connection Database

Source: Internet
Author: User

We all know that the BS program can be set by the configuration file database information, the program through the reading configuration file can get the corresponding database connection string, in fact, CS program can also do so, in the project root directory of the new configuration File App. Config file, in the add configuration information, such as:

<?XML version= "1.0" encoding= "Utf-8"?><Configuration>    <appSettings>        <AddKey= "Dbreader"value= "server=127.0.0.1;uid=***;p wd=***;d atabase=***; Max Pool size=300; " />    </appSettings></Configuration>

In this case, the configuration file can be read in the background,

string conn = system.configuration.configurationsettings.appsettings["dbreader" ];

In order not to use system.configuration.configurationsettings.appsettings["Dbreader" every time to get configuration information, we can write a method to get the configuration information

 Public Static string Get (string  key)        {            return  System.configuration.configurationsettings.appsettings[key];        }

When we call this method, we get the configuration information through the Get () method.

string connstr = Config.get ("dbreader");

Config is a class library, so we get the information on the configuration file.

WinForm Program Connection Database

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.