The following describes how to use the web.config configuration file in VS2005 to perform database connection operations and enable the connection pool of the SQL Server database. I believe it will be helpful to friends who are already familiar with VS2003 and have just entered the 05 environment.
First of all, in 05, by default, web.config is not automatically generated for the application. When the application is run for the first time, a prompt of Debuging Not Enabled will appear. Click the OK button and a web.config will be generated for the application. .config configuration file. In the <configuration> element, there are already the following two node elements:
<appSettings/>
<connectionStrings/>
In 03, the database connection configuration is specified in <appSettings/> by add key=" connStr " value = " "; in 05, the "connectionStrings element specifies the database connection character for ASP.NET applications and ASP.NET functions. A collection of strings (in the form of name/value pairs). In previous versions of ASP.NET, connection strings were stored in appSettings, such as sessions, memberships, personalizations, and role managers. Functionality relies on the connection string being stored in the connectionStrings element. You can also use the connectionStrings element to store your own application's connection string.
You can replace <connectionStrings/> with the following code:
<connectionStrings>
<add
name="CONNSTRING"
connectionString="data source =localhost;uid =sa;pwd=;database=Book;pooling=true"/> //Note: pooling can also be specified later through code
</connectionStrings>
You can read it in the application like this:
private readonly string SQLCONNECTIONSTRING = ConfigurationManager.ConnectionStrings["CONNSTRING"].ConnectionString;
This article comes from the CSDN blog. Please indicate the source when reprinting: http://blog.csdn.net/yunazhaozile/archive/2009/12/23/5060762.aspx