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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit ChoudharyPosted Mar 26, 2010, 9:22 AM
- 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.
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