In website development, database operations are frequently used, ASP. NET. configure the database connection code in config and then call the database connection code in the program. The advantage of this is that when 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 be modified.
In website development, database operations are frequently used, ASP. NET. configure the database connection code in config and then call the database connection code in the program. The advantage of this is that when 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 be modified.
In website development, database operations are frequently used, ASP. NET. configure the database connection code in config and then call the database connection code in the program. The advantage of this is that when 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, which are appSettings and connectionStrings. When you configure the database connection code using appSettings and connectionStrings, you can Add the following code:
1. appSettings
2、connectionStrings
Difference between appSettings and connectionStrings:
(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.
Call example:
1st string strSqlConString = System. Configuration. ConfigurationManager. receivettings ["mySqlConnection"];
2nd string strSqlConString = System. Configuration. ConfigurationManager. ConnectionStrings ["mySqlConnection"]. ToString ();