how to compress & fix database access 2007 by C# code?
my C# winforms program work's on database acc开发者_运维知识库ess 2007
this database became swollen.
is there any way for compress and fix this database by C# code ?
if i do it manual (through access) it became less swollen
thank's in advance
You could use the /compact
command line argument for msaccess.exe or you can use interop and do something like this Compact And Repair that I found on code project.
C# sample using MS Access Command Line...
var mdbFileName = Path.GetFullPath("youraccessdb.mdb");
if (!File.Exists(mdbFileName))
throw new FileNotFoundException(
"Could not find Access Database",
mdbFileName);
var programFiles = Environment.GetEnvironmentVariable("ProgramFiles");
var accessPath = Path.Combine(
programFiles,
@"Microsoft Office\Office12\MSACCESS.EXE");
if (!File.Exists(accessPath))
throw new FileNotFoundException(
"Could not find MSACCESS.EXE",
accessPath);
var commandArgs = string.Format("/compact \"{0}\"", mdbFileName);
var process = Process.Start(accessPath, commandArgs);
process.WaitForExit();
if (process.ExitCode != 0)
throw new ApplicationException(string.Format(
"Access Exited with Error Code [{0}]",
process.ExitCode));
精彩评论