Article ID: 306287 - View products that this article applies to.
This article was previously published under Q306287
Neither ActiveX Data Objects (ADO) nor ADO .NET provide the means to compact or repair Microsoft Access databases. However, you can accomplish this task by using the Microsoft Jet OLE DB Provider and Replication Objects (JRO) that was introduced with Microsoft Data Access Components (MDAC) version 2.1. ADO .NET allows the use of COM-based object libraries through the Interop layer.
This article demonstrates how to compact an Access database by using Visual Basic .NET.
Steps to build example
PitfallsIn order to compact a database, the Jet Database Engine requires exclusive access to the database file. Attempting to compact a database file that is currently in use will result in an exception. This exception can be caught using a Try...Catch structure.
For more details about the .NET Framework and the COM Interop layer, see:
Exposing COM Components to the .NET FrameworkFor more information about using ADO and JRO to compact Access Databases, click the following article number to view the article in the Microsoft Knowledge Base:
(http://support.microsoft.com/kb/230501/ )How to compact Microsoft Access database via ADO