If you use web. config to save the database connection, it is undoubtedly the best form, which facilitates database migration and changes, and other uncertainties for easy maintenance. However, you can find some database connections such as saving SQL on the network. If it is an access connection, it is not that convenient. However, you can use the following measures to ensure the access connection.
1. Add in Web. config:
<Deleetask>
<Add key = "connstring"
Value = "provider = Microsoft. Jet. oledb.4.0; Data Source = {0} \ database \ digestdb. config"/>
</Appsettings>
Note that the data name is digestdb. config (to ensure security, change the suffix) and put it under the directory database.
2. classes operated in the database orCodeIt is referenced as follows:
Private Static string connstring = string. Format (system. configuration. configurationsettings. deleettings ["connstring"],
System. Web. httpcontext. Current. server. mappath ("."));
3. directly use the database connection in the code
For example, in a separate class:
Private Static string connstring = string. Format (system. configuration. configurationsettings. deleettings ["connstring"],
System. Web. httpcontext. Current. server. mappath ("."));
These things are searched out instead of coming out. Haha :)