The difference between appsettings and connectionstrings

Source: Internet
Author: User

The difference between appsettings and connectionstrings

AppSettings was used in the asp.net1.1 period, and in the. NET Framework 2.0, a new connectionstrings was added.

1.<connectionstrings>
<connectionStrings>
<add name= "connectionStringName" connectionstring= "Data source= server name; Initial catalog= database name; User id= users; password= Password "
Providername= "System.Data.SqlClient"/>
</connectionStrings>

Or

<connectionStrings>
<add name= "connectionStringName" connectionstring= "sever= server name; database= database name; User id= users; password= Password "
Providername= "System.Data.SqlClient"/>
</connectionStrings>

In the <connectionStrings>, on the page can also refer to <%$ connectionstring:name%>.

2.<appsettings>

<add key= "connectionStringName" value= "data source= server name or ip;initial catalog= database name; Persist Security Info=false;user id= user; password= password; packet size=4096 ">
</add>

1) AppSettings is commonly used in 2003, and Connectionstrins is commonly used in 2005.
2) Benefits of using ConnectionString:
First: The connection string can be encrypted, using an encryption tool of Ms.
Second: The data source control can be set directly, without having to write code to read it and assign it to the control.
Third: Easy to replace the database platform, such as the Oracle database, just modify the providername.
3) write in <appsettings > to retrieve the value with system.configuration.configurationmanager.appsettings["name".
Write in <ConnectionStrings> use system.configuration.configurationmanager.connectionstrings["name"] to retrieve the value.

In the. NET Framework 2.0, The ConfigurationManager class has added two properties appsettings and connectionstrings specifically used to obtain the data for the configuration file appsettings and connectionstrings sections, using the following methods:

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 <appSettings>
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>

Category: C #, ASP.

The difference between appsettings and connectionstrings

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.