How to Compact and Repair ms-access database using vb.net code
I am using ms-access as a backend in my project. I want to know how to compact and repair database when i close that application
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Amit ChoudharyRank #145 · 15.8K reputationPosted Mar 26, 2010, 5:22 AM EDT
- Open a new Visual Basic .NET console application.
- In the Solution Explorer window, right-click the References node and select Add Reference.
- In the Add Reference dialog box, click the COM tab, and then select Microsoft Jet and Replication Objects 2.x Library. Click Select to add it to Selected Components. Click OK.
- A warning will be displayed if there is no wrapper found for the selected library. ClickYes to generate a wrapper. Microsoft ActiveX Data Objects Library (ADODB) and JRO references will be added to the project's References.
- In the Solution Explorer window, right-click Module1.vb and click View Code.
- Delete all of the code from the code window.
Here is the code Copy and paste it to your module:Note In this step, x is a placeholder for the actual version number of the Microsoft Jet and Replication Objects Library component.
Module Module1 Sub Main() Dim jro As JRO.JetEngine jro = New JRO.JetEngine() jro.CompactDatabase("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\nwind.mdb", _Change the path to the Source and Destination .mdb files as appropriate. Press F5 to build and run the project. You can change the providers if you want it to higher versions.
The compacted database will be in Access 2000 (Jet 4.0) format.
Please mark as answer if it helps