简体   繁体   中英

How to convert a .mdb file with a password to a .accdb file with C#

I am writing a C# program which among other things need to convert a password-protected .mdb Access database to password-protected .accdb file. The function would look a little something like:

public int M2AConvert( string password, string newPath, stringOldPath )

The code I have right now is:

Microsoft.Office.Interop.Access.Application accessApp = new 
Microsoft.Office.Interop.Access.Application();
accessApp.Visible = true;
string sourceFile = oldPath;
string desFile = newPath;
accessApp.SysCmd((Microsoft.Office.Interop.Access.AcSysCmdAction)603, sourceFile, desFile);

This doesn't seem to work with password-protected files, hence the quesion.
Any help would be appreciated.

Used DbEngine with the following code to allow conversion with a password:

using Microsoft.Office.Interop.Access.Dao;
...
DBEngine daoEng = new DBEngine();
daoEng.CompactDatabase(dbNameSrc, dbNameDest, LanguageConstants.dbLangGeneral, dbVersion, pwd);

where dbVersion is dbVersion120 for .mdb to .accdb. Other dbVersion types can be used to convert between .accdb to .mdb, but keep in mind dbVersion40 is for Jet 4.0 which is the most recent version of the provider for .mdb files.
All dbVersion conversion types are listed here: Microsoft Docs

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM