问题
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