ASP. NET connection Access Server database Path Problem verified to solve the problem

Source: Internet
Author: User

 

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.