Configure the connection string for ASP. NET Access access

Source: Internet
Author: User
Because access is a file database, you must be able to map access to access files in ASP. NET:

Method 1: Set the connection string in deleettings

Web. config Configuration

<Deleetask> < Add key = " Provider " Value = " Provider = Microsoft. Jet. oledb.4.0; Data Source = " />
< Add key = " Dbpath " Value = " ~ /DB \ data. MDB " /> // Note that ~ must be added ~ /, Representing the root directory </Appsettings>

 

Concatenate database connection strings through server. Map ()

  /// <Summary>
/// Connection string
/// </Summary>
Private String connectionstring = System. configuration. configurationmanager. configurettings [ " Provider " ]. Tostring () + System. Web. httpcontext. Current. server. mappath (configurationmanager. deleetpipeline [ " Dbpath " ]) + " ; " ;

 

Method 2: connect to access using sqldatasource

Web. config Configuration

< Connectionstrings >
< Add name = " Websiteconnectionstring " Connectionstring = " Provider = Microsoft. Jet. oledb.4.0; Data Source = | datadirectory | aisino_data.mdb " Providername = " System. Data. oledb " /> // Note: datadirectory cannot be changed. Otherwise, "invalid file name error" will occur "! This indicates that it cannot be modified. Your database must be stored in app_data.

 

In this way, access through configurationmanager. connectionstrings ["websiteconnectionstring"]. connectionstring.

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.