Microsoft Access Compact and Repair using C# .accdb files

£可爱£侵袭症+ 提交于 2019-12-08 05:18:59

问题


I need to Compact and Repair .accdb (last MS Access) version using C#

I tried using this:

var jroEngine = new JRO.JetEngineClass();

var old_ = Provider=Microsoft.ACE.OLEDB.12.0;Data Source='c:\a.accdb';
var new_ = Provider=Microsoft.ACE.OLEDB.12.0;Data Source='c:\b.accdb';

jroEngine.CompactDatabase(old_, new_);
Marshal.ReleaseComObject(jroEngine);

There is an error:

{"Invalid argument."}


回答1:


This is probably the most straightforward way to do it:

string sourceDbSpec = @"C:\Users\Public\a.accdb";
string destinationDbSpec = @"C:\Users\Public\b.accdb";

// Required COM reference for project:
// Microsoft Office 14.0 Access Database Engine Object Library
var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngine();
try
{
    dbe.CompactDatabase(sourceDbSpec, destinationDbSpec);
}
catch (Exception e)
{
    Console.WriteLine("Error: " + e.Message);
}


来源:https://stackoverflow.com/questions/29201611/microsoft-access-compact-and-repair-using-c-sharp-accdb-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!