In website development, database operations are frequently used. In ASP. NET, you can configure database connections in Web. config.CodeAnd thenProgramWhen the database connection code needs to be changed, we only need to modify the web. the database connection code in config does not need to modify the database connection code on each page.
There are two methods to configure the database connection code in ASP. NET:AppsettingsAndConnectionstrings. You can add the following code under <configuration> When configuring the database connection code using appsettings and connectionstrings:
1. appsettings
<Appsettings>
<AddKey= "Conn"Value= "Server = server name; database = database name; uid = user name; Password = password ;"/>
</Appsettings>
2. connectionstrings
<Connectionstrings>
<AddName= "Conn"Connectionstring= "Dserver = server name; database = database name; uid = user name; Password = password"Providername= "System. Data. sqlclient" />
</Connectionstrings>
Appsettings and connectionstrings :( from http://www.cnblogs.com/kerry1986/archive/2009/07/08/1518895.html)
(1) appsettings are commonly used in 2003 and connectionstrings are commonly used in 2005;
(2) advantages of using connectionstrings:
First, you can encrypt the connection string by using an encryption tool of Ms;
Second, you can directly bind a data source control without having to write code to read it and then 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 in the deleettings. configuration. configurationmanager. appsettings ["keyname"] to obtain the database connection code value. It is written in connectionstrings and used in system. configuration. configurationmanager. connectionstrings ["name"] gets the database connection code value.