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.
2.0, added connectionstrings to obtain 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 ();
}
}
<Connectionstrings>And<Deleetask>This difference
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> can also be referenced on the page like this <% $ 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>
Note:
(1) appsonstrins 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 bound without having to writeCodeRead it and assign it to the control.
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.