Description of the App. Config app

Source: Internet
Author: User


The encapsulation of the link string that accesses the database (MS everything in the package, get us the original Yue (weak) (wisdom)), well, you can explain that can easily change the link to change the configuration, without moving the main program------Isolation (isolation-protection; You should be familiar with power distribution)

I still trust the two properties of MSDN first ConfigurationManager class, two properties can achieve the goal

Example above

AppSettings:

<?xml version="1.0" encoding="utf-8" ?>< configuration>    <configSections>    </configSections>    <appSettings>        <add key="CarManager.Properties.Settings.DataConnectionString"            value ="Data source=rtdz-006;initial catalog=data; User ID=TTNZ; password=12345"             />    </appSettings></configuration>

Link

New SqlConnection (configurationmanager.appsettings[0]. ToString ());

————————————————————————————————
ConnectionStrings

<?xml version="1.0" encoding="utf-8" ?>< configuration>  <connectionStrings>    <add name="myconn" connectionstring="Data source=.;i Nitial Catalog=northwind;         Persist Security info=true; User Id=sa; password="/>  </connectionStrings></configuration>

Link

string connstr = configurationmanager.connectionstrings["myconn"]. ConnectionString;

————————————————————————————————————

Note: using System.Configuration; to add

Reference to add System.Configuration

Description of the App. Config app

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.