Storing connection string in the web.config file
To store the database connection string in the web.config file perform
the following steps:
- Open the web.config file.
- Add the appSetting section.
<configuration>
<appSettings>
<add key="ConnectionString"
value="Provider=SQLOLEDB.1;Integrated Security=SSPI;Initial Catalog=Northwind">
</appSettings>
</configuration>
- Save the web.config file.
- Open the database user class
(<DatabaseCodeName>).
- Replace the body of the CreateConnection method.
string
dbConnection = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
return new System.Data.OleDb.OleDbConnection(dbConnection);