Howto:compacting Microsoft Access Database via ADO
--------------------------------------------------------------------------------
The information in this article applies to:
ActiveX Data Objects (ADO), versions 2.1, 2.5, 2.6
Microsoft OLE DB Provider for Jet, version 4.0
--------------------------------------------------------------------------------
SUMMARY
Although ADO specification does not provide objects to compact or repair Microsoft Access databases, this capability can B E achieved by using the ADO extension:microsoft Jet OLE DB Provider and Replication Objects (JRO). This capability is implemented for the "the" the "the" the "the" the "the" in the JET OLE DB Provider version 4.0 (Msjetoledb40.dll) and JRO Versi On 2.1 (Msjro.dll). These DLLs files are available after the install of MDAC 2.1. Can download the latest version of MDAC from the following Web site:
Universal Data Access Web Site
More information
To repair and compact an Access database using ADO, MDAC 2.1 or later must is properly on the installed. The following are the main steps to compact a Microsoft Access database using Visual Basic and Visual C + +:
Visual basic:compacting an Access Database via ADO
The Visual Basic IDE, on the Projects menu, click References.
Add Microsoft Jet and Replication Objects x.x Library, where (x.x is greater than or equal to 2.1).
Add the following lines of code to Visual Basic, replacing the data source and destination database Pathsif needed:
Dim JRO as JRO. JetEngine
Set JRO = New JRO. JetEngine
Jro.compactdatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\nwind2.mdb", _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\abbc2.mdb; Jet oledb:engine type=4 "
Note:in DAO 3.60, the RepairDatabase method is no longer available. The above code shows the use of the
CompactDatabase method. This is replaces the DAO 3.5 RepairDatabase method.
Visual C + +: Compacting an Access Database via ADO
Besides #import, the Msado15.dll (MDAC2.1), add the following #import statement to generate the wrapper classes for JRO to Your. CPP classes (alternatively, can generate the wrapper classes more efficiently by using the No_implementation D implementation_only attributes of the #import pre-processor statement):
#import "C:Program filescommon FILESSystemadoMSJRO.DLL" No_namespace Add the following (specifying your own source and de Stination database paths to the. cpp file where
Want to compact the database:
...
Try
{
Ijetengineptr Jet (__uuidof (JetEngine));
Jet->compactdatabase (
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\nwind2.mdb",
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\abbc.mdb;"
"Jet oledb:engine type=4");
}
catch (_com_error &e)
{
:: MessageBox (NULL, (LPCTSTR) e.description (), "", MB_OK);
}
Note:the Jet Oledb:engine type=4 is only for Jet 3.x format MDB files. If This value is left, the
The database is automatically upgraded to the 4.0 version (Jet oledb:engine type=5). The following table
For appropriate values for Jet oledb:engine Type:
Jet Oledb:engine Type jet x.x Format MDB Files
1 JET10
2 JET11
3 jet2x
4 jet3x
5 jet4x
REFERENCES
For additional information, please have the following article in the Microsoft knowledge Base:
Q230496 compacting Microsoft Access database via OLE DB
Additional Query Words:compactdatabase repairdatabase reindex
keywords:kbado210 kbjet kbprovider kbVBp600 kbvc kbgrpdsvcdb kbgrpdsmdac kbdsupport kbADO250 tslic_tslic
kbADO260
Issue Type:kbhowto
Technology:kbauddeveloper kbadosearch kbADO210 kbADO250 kbADO260 kboledbsearch
Kboledbprovsearch