An exception occurred while accessing an unrecognized database connected to accdb.

Source: Internet
Author: User

The database suffix before access07 is *. mdb, and the connection string is writtenProvider =Microsoft. Jet. oledb.4.0; Data Source = c: \ myfolder \*.MDB; Persist Security info = false;

However, access07 and access10 change the suffix to *. accdb. When the above connection is used, an "Unrecognized database format" exception will be reported.

Note thatMicrosoft. Jet. oledb.4.0The oledb connection method of is relatively old, and later oledb connection method will be changedMicrosoft. Ace. oledb.12.0.

The changed Connection becomesProvider =Microsoft. Ace. oledb.12.0; Data Source = c: \ myfolder \*.Accdb; Persist Security info = false;



Tips for beginners:

In Asp.net, the connection string is often written in Web. config. However, the access connection string is the absolute location of the database. That is, the drive letter:/folder/file, which leads to the need to change the path after the file is copied. In fact, you can useProgramTo obtain the absolute path of the database file. The details are as follows:

Write only the database file name in Web. config.(Generally, database files are stored in the app_data folder because of the security)

 

 <Appsettings>
<AddKey= "Connstring"Value= "App_data \ managedb. accdb"/>
</Appsettings>

Write the following method to obtain the string in the dbhelper class:

 Public Static StringConnectionstring ="Provider = Microsoft. Ace. oledb.12.0; Data Source ="+ Appdomain. currentdomain. basedirectory + configurationsettings. deleettings ["Connstring"];

Obtain the absolute path of the database through appdomain. currentdomain. basedirectory.


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.