The Apps Tutorial ettings is an ASP tutorial. net1.1 period, in. NET Framework 2.0, new connectionstrings specifically used to get configuration files in the ConfigurationManager class
The appsettings and connectionstrings sections are used in the following ways:
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 ();
}
}
AppSettings is used during the ASP.net tutorial 1.1, and in the. NET Framework 2.0, connectionstrings is added.
1.<connectionstrings>
<connectionstrings>
<add name= "connectionStringName" connectionstring= "data source= server name; Initial catalog= database tutorial 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= username; password= password "
Providername= "System.Data.SqlClient"/>
</connectionstrings>
In <connectionstrings>, in the page can also quote <%$ 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 The benefits of using ConnectionString:
First: The connection string can be encrypted, using one of MS's encryption tools.
Second: Directly state the data source control, but do not have to write code read out and then assign to the control.
Third: Easy to replace the database platform, such as the Oracle database, just modify the providername.
3 write in <appsettings > retrieve the value with system.configuration.configurationmanager.appsettings["name".
Write in <connectionstrings> retrieve values with system.configuration.configurationmanager.connectionstrings["name".
In the. NET Framework 2.0, The ConfigurationManager class has added two properties appsettings and connectionstrings specifically to get the data for the profiles 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>