How to compress a Microsoft Access database via ADO

Source: Internet
Author: User
Tags compact ole wrapper access database knowledge base microsoft access database
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 Files\Common Files\system\ado\msjro. DLL "No_namespace Add" following (specifying your own source and destination database paths) to the. cpp file where yo U
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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.