Differences between appsettings and connectionstrings in Web. config

Source: Internet
Author: User
Differences between appsettings and connectionstrings in Web. config

In ASP. NET programming, it is found that you can write the connection data string configuration in two ways, namely, etettings and connectionstrings.

Appsettings is used in the ASP. net1.1 period. In. NET Framework 2.0, connectionstrings is added specifically to get configuration files in the configurationmanager class.

Use the following data in the appsettings and connectionstrings sections:

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 = "connectionstringname" connectionstring = "Data Source = server name; initial catalog = database name; user id = user; Password = password"
Providername = "system. Data. sqlclient"/>
</Connectionstrings>

In <connectionstrings>, You can reference <% $ connectionstring: name %>.

2. <appsettings>:

<Add key = "connectionstringname" value = "Data Source = server name or IP address; initial catalog = database name; persist Security info = false; user id = user; Password = password; packet size = 4096 ">
</Add>

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.