Differences between appsettings and connectionstrings in the ASP. NET configuration file

Source: Internet
Author: User
Tags connectionstrings

In. NET Framework 2.0, the configurationmanager class adds two attributes: deleettings and connectionstrings, which are used to obtain data in the configuration file appsettings and connectionstrings sections. The usage is as follows:

Using system. configuration;
Public partial class _ default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Label1.text = configurationmanager. connectionstrings ["connectionstringsname"]. tostring ();
Label2.text = configurationmanager. appsettings ["appsettingsname"]. tostring ();
}
}

 

The difference between <connectionstrings> and <etettings>
1. <connectionstrings>
<Connectionstrings>
<Add name = "syxtconnectionstring" connectionstring = "Data Source = leike; initial catalog = syxt; user id = sa; Password = sa"
Providername = "system. Data. sqlclient"/>
</Connectionstrings>

2. <appsettings>:

<Add key = "connectionstring1" value = "Data Source = 192.168.123.201; initial catalog = webmedlink; persist Security info = false; user id = sa; Password = ksdchagd2004; packet size = 4096 ">
</Add>

Note:

(1) appsonstrins are commonly used in 2003 and connectionstrins are commonly used in 2005.

(2) advantages of using connectionstring:

First, you can encrypt the connection string by using an encryption tool of Ms.

Second, data source controls that can be directly bound without having to writeCodeRead it and assign it to the control.

Third, you can easily change the database platform. For example, if you change to an Oracle database, you only need to modify the providername.

(3) Use System. configuration. configurationmanager. deleetask[ "name"] to retrieve the value in <deleetask>.

In <connectionstrings>, use system. configuration. configurationmanager. connectionstrings ["name"] to retrieve the value.

 

Related Article

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.