如此处所述,我正在使用 C# 将表从 SQL Server 重建到 Access 多亏了我收到的帮助,我可以完成该过程,但由于 .accdb 文件非常大,我需要在之后压缩和修复它们。为此,我使用了此处的标记答案。奇怪的是,我只能将“Microsoft Office 16.0 Access Database Engine Object Library”的引用添加到我的项目中。
using Microsoft.Office.Interop.Access.Dao;
var engine = new DBEngine(); // Exception
var destFile = Path.GetFileNameWithoutExtension(filepath) + "_Compact" + ".accdb";
var destFilePath = Path.Combine(Path.GetDirectoryName(filepath), destFile);
engine.CompactDatabase(filepath, destFilePath);
在初始化 DBEngine - 对象时,抛出异常:
Retrieving the COM class factory for component with CLSID {CD7791B9-43FD-42C5-AE42-8DD2811F0419} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
另外,有没有办法使用 ADOX 来完成这项任务,因为我已经在使用它来创建我的目录?