Is it possible to \"compact and repair\" an Access database programmatically somehow (using ADOX, using OleDbConnection etc.)?
This solution works with the Access 2010 Database Engine:
Required reference:
Microsoft.Office.interop.access.dao
Code:
public void CompactDb(
string sourceFilePath, string destFilePath, string password)
{
var dbEngine = new Microsoft.Office.Interop.Access.Dao.DBEngine();
dbEngine.CompactDatabase(sourceFilePath, destFilePath,
";pwd=" + password, null, ";pwd=" + password);
}
(The sourceFilePath and destFilePath should not be the same!)
CompactDatabase method parameters (from reflection):
void CompactDatabase(
string SrcName, string DstName,
object DstLocale = Type.Missing,
object Options = Type.Missing,
object SrcLocale = Type.Missing);
Make sure you run it under the same platform as the AccessDatabaseEngine (or Office) you installed (x86/x64).