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