Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to compact Msaccess database using c#

Tags:

c#

ms-access

is it possible to compact the Msaccess database using c# if so let me know the way?

like image 679
subash Avatar asked Sep 14 '26 12:09

subash


2 Answers

You can try something like this

public static void CompactAndRepair(string accessFile, Microsoft.Office.Interop.Access.Application app)
        {
            string tempFile = Path.Combine(Path.GetDirectoryName(accessFile),
                              Path.GetRandomFileName() + Path.GetExtension(accessFile));

            app.CompactRepair(accessFile, tempFile, false);
            app.Visible = false;

            FileInfo temp = new FileInfo(tempFile);
            temp.CopyTo(accessFile, true);
            temp.Delete();
        }

See also Use the CompactRepair method of the Application object to compact and repair the database

like image 101
Adriaan Stander Avatar answered Sep 17 '26 02:09

Adriaan Stander


...
//invoke a CompactDatabase method of a JRO object
//pass Parameters array
objJRO.GetType().InvokeMember("CompactDatabase",
    System.Reflection.BindingFlags.InvokeMethod,
    null,
    objJRO,
    oParams);
...

See more details at http://www.codeproject.com/KB/database/mdbcompact_latebind.aspx

like image 35
Dror Avatar answered Sep 17 '26 02:09

Dror



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!