简体   繁体   English

如何使用 C# 将带有密码的 .mdb 文件转换为 .accdb 文件

[英]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.我正在编写一个 C# 程序,其中需要将受密码保护的 .mdb Access 数据库转换为受密码保护的 .accdb 文件。 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:将 DbEngine 与以下代码一起使用以允许使用密码进行转换:

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.其中 dbVersion 是 dbVersion120,用于 .mdb 到 .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.其他 dbVersion 类型可用于在 .accdb 到 .mdb 之间转换,但请记住 dbVersion40 用于 Jet 4.0,它是 .mdb 文件提供程序的最新版本。
All dbVersion conversion types are listed here: Microsoft Docs此处列出了所有 dbVersion 转换类型: Microsoft Docs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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