ASP. NET connection Access Server database Path Problem
Use ASP as a small project. net + ACCESS database, there is always a database path problem. My previous solution is to upload the link string to the data access layer in the form of parameters each time I access the database, which is quite troublesome to implement, this time I found a better solution. This is my final solution (such as the question) ^_^
Solution:
Configure the ACCESS database driver and database file name in Web. config.
Please refer to the code
<Deleetask>
<Add key = "dbdriver" value = "provider = Microsoft. Jet. oledb.4.0; Data Source ="/>
<Add key = "dbname" value = "company. mdb"/>
</Appsettings>
Obtain the ACCESS database link string in the database access layer, such as oledbhelper. CS.
/** // <Summary>
/// Obtain the database connection string from web. config
/// </Summary>
// Obtain the database name from the configuration file
Public static readonly string dbname = configurationmanager. receivettings. Get ("dbname"). tostring ();
// Obtain the database driver from the configuration file
Public static readonly string dbdriver = configurationmanager. deleetmanager. Get ("dbdriver"). tostring ();
// Obtain the database connection string
Private Static string dbconnectionstring = dbdriver + httpcontext. Current. server. mappath (httpcontext. Current. Request. applicationpath + "/app_data/") + dbname;
// Create a database connection object
Private Static oledbconnection oledbconn = new oledbconnection (dbconnectionstring );
After this setting, you can use the above code to access the database in any subdirectory correctly.
Reference address: http://www.codesky.net/article/doc/201004/20100417061220.htm