我需要使用C#
来压缩和修复.accdb(最后一个MS Access)版本我试过用这个:
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);
有一个错误:
{"参数无效。"}
答案 0 :(得分:2)
这可能是最简单的方法:
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);
}