VB 2010 MS Access Compact and Repair Database
MS Access 2003/2007/2010 Compact and Repair
|VB.Net Compact and Repair Database - MS Access|
This article demonstrates how to compact an Access database by using Visual Basic .NET.
- Microsoft Visual Basic .NET
- Microsoft Jet and Replication Objects 2.1, 2.5, or 2.6 Library - For *.mdb file (200-2003)
- Microsoft.Office.interop.access.dao Assembly - For *.accdb file (2007)
Steps to build example
- 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
- In the Add Reference dialog box, click the NET tab, and then select Microsoft.Office.interop.access.dao. (Run-time version : v1.1.4322) (File version : 220.127.116.11 means ms access 2007) Click Select to add it to Selected Components. Click OK
- Note In this step, x is a placeholder for the actual version number of the Microsoft Jet and Replication Objects Library component.
- A warning will be displayed if there is no wrapper found for the selected library. Click Yes 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.
- Copy the following code and paste it into the code window:
- Change the path to the Source and Destination .mdb files as appropriate. Press F5 to build and run the project.
The compacted database will be in Access 2000 (Jet 4.0) format. For a different Jet format, see "References."