Compact Access Database from CSharp

  • Thread starter Thread starter Benny Raymond
  • Start date Start date
B

Benny Raymond

I realized that as I add and delete rows in my database that the size
never goes down... just up and up and up and ... well you get the
picture. I know that when you're working through access you can select
"Compact and Repair database..." from the Tools menu which removes all
of the rows that no longer exist... The only problem is that I cannot
figure out how to make the database do this from my program, add to the
fact that my users may not have Access, nor would I want them to have to
open up the database every once in a while and compact it if they did
have access.

So, is it possible to send a command over OleDb that compacts the database?

Thanks in advance,
Benny
 
No. Possibly through adox which involves interop. Take a look at VSTO or
just instantiate an Access object (again interop).
 
You have to use the JRO library.

Add a reference to "Microsoft Jet and Replication Objects 2.6 Library" (COM component)

string FileSource = "MyAccessFile.mdb";
string SourceConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + FileSource;
string DestConnection = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + "FileTmp.mdb";

if (System.IO.File.Exists("FileTmp.mdb"))
System.IO.File.Delete("FileTmp.mdb");

JRO.JetEngineClass objJet = new JRO.JetEngineClass();
objJet.CompactDatabase(SourceConnection, DestConnection);

System.IO.File.Delete(FileSource);
System.IO.File.Move("FileTmp.mdb", FileSource);
 
carion1 said:
No. Possibly through adox which involves interop. Take a look at VSTO or
just instantiate an Access object (again interop).
instantiating an Access object requires the end user to have access
though right?
 
Back
Top