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.