Access Datenbank komprimieren und reparieren
/// <summary>
/// Compacts the access DB.
/// </summary>
/// <param name="connectionString">The connection string.</param>
/// <param name="filename">The filename.</param>
public static void CompactAccessDB(string connectionString, string filename)
{
object objJRO = Activator.CreateInstance(Type.GetTypeFromProgID("JRO.JetEngine"));
object[] oParams = new object[] { connectionString, "Provider=Microsoft.Jet.OLEDB.4.0;Data" + " Source=C:\\tempdb.mdb;Jet OLEDB:Engine Type=5" };
objJRO.GetType().InvokeMember("CompactDatabase", BindingFlags.InvokeMethod, null, objJRO, oParams);
File.Delete(filename);
File.Move("C:\\tempdb.mdb", filename);
Marshal.ReleaseComObject(objJRO);
}
3 Kommentare zum Snippet