c# .accdb格式access数据库压缩

1.安装nuget程序包 Microsoft.Office.Interop.Access.Dao

c# .accdb格式access数据库压缩_第1张图片

2.编写代码

string tempFile = Path.Combine(Path.GetDirectoryName(accessFile),
                              Path.GetRandomFileName() + Path.GetExtension(accessFile));
            var dbe = new Microsoft.Office.Interop.Access.Dao.DBEngine();
            try
            {
                dbe.CompactDatabase(accessFile, tempFile);
                FileInfo temp = new FileInfo(tempFile);
                temp.CopyTo(accessFile, true);
                temp.Delete();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
            }

你可能感兴趣的:(编程)