how to compact Msaccess database using c#

后端 未结 3 636
情话喂你
情话喂你 2021-01-15 12:44

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

3条回答
  •  北海茫月
    2021-01-15 13:24

    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

提交回复
热议问题