Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compact/Repair an Access DB from VB.NET

Status
Not open for further replies.

PogoWolf

Programmer
Mar 2, 2001
351
US
Is there a way to compact a database from code, WITHOUT dropping back to RDO, in VB.NET?

I'm not seeing any commands for the OLEDB object that will allow me to compact it..



The PogoWolf
 
perhaps.. Though I was hoping to get around the need to reference aother oject...

Need to have MDAC2.6 installed on the computer (VS.NET installs MDAC2.7)

will this work with MDAC 2.7, then?


either way, I'll give it a shot.. thanks!!!!



The PogoWolf
 
I guess it will work with 2.7.

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Well that did work, and I thank you so much for the help.

Code:
'// Compact the DB.
Dim jro As JRO.JetEngine
jro = New JRO.JetEngine()
jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\DataBase\RALPHhz.mdb", _
                    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=.\DataBase\RALPHhz2.mdb;Jet OLEDB:Engine Type=5")
Kill (".\DataBase\RALPHhz.mdb")
Rename(".\DataBase\RALPHhz2.mdb", ".\DataBase\RALPHhz.mdb")

but there's got to be a better way.. this just seems to be a bit much to me for being .NET.. =/


The PogoWolf
 

Thanks for the great link.

Just so this thread is complete, I am posting two instructions needed before the code is entered.

Step 1:
Need to have MDAC2.6 installed on the computer (VS.NET insta­lls MDAC2.7)


Step 2:
write-click References in your VB.NET or C#.NET project, sel­ect Add
Reference. Click Com Tab and double click on "Microsoft Jet­ and
Replication Objects 2.6 Library" then click "OK" button twic­e. This will
add ADODB and JRO references to the project.


Step 3:
Use the following code (VB.NET):


Dim jro As JRO.JetEngine
jro = New JRO.JetEngine()
jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.­0;Data
Source=C:\...\nwind.mdb", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\...\newnwind.mdb;Jet OLEDB:Engine Type=5")


Engine Type = 5 for Jet 4.0 database (Access 2000 format).


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top