Among them, the apps tutorial ettings is used in the asp tutorial. net1.1. In. net framework 2.0, connectionstrings is added specifically to get the configuration file 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 ();
}
}
Appsettings is used in the asp.net tutorial 1.1. in. 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 = user; password = password"
Providername = "system. data. sqlclient"/>
</Connectionstrings>
Or
<Connectionstrings>
<Add name = "connectionstringname" connectionstring = "sever = server name; database = database name; user id = user; password = password"
Providername = "system. data. sqlclient"/>
</Connectionstrings>
In <connectionstrings>, You can reference <% $ connectionstring: name %>.
2. <deleetask>
<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>
1) appsettings 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 attached without having to write code to read them and then assign them to the controls.
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.
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>