ASP. NET connection Access database method

Source: Internet
Author: User
Tags database join httpcontext

The


configures the Access database driver and database file names in Web. config.
See code
<appSettings>
<add key= "Dbdriver" value= "provider=microsoft.jet.oledb.4.0; Data Source = "/>
<add key=" DBName "value=" Company.mdb "/>
</appSettings>
At the database access layer, as Gets the Access database link string in OleDBHelper.cs.
/**////<summary>
//Get the database join string from Web. config
//</summary>
//Get the database name from the configuration file
Public Static readonly String DBName = ConfigurationManager.AppSettings.Get ("DBName"). ToString ();
//Get database driven from configuration file
public static readonly string dbdriver = ConfigurationManager.AppSettings.Get ("Dbdriver"). ToString ();
//Get database connection string
Private static string dbconnectionstring = Dbdriver + HttpContext.Current.Server.MapPath ( HttpContext.Current.Request.ApplicationPath + "/app_data/") + DBName;
//Establish database connection object
private static OleDbConnection oledbconn = new OleDbConnection (dbconnectionstring); After the
is set up, you can access the database correctly through the above code, regardless of any subdirectories.

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.