How do you use ADO to compress or repair MS access files in Access?

Source: Internet
Author: User
Tags format ole access
access|ado| compression
How do you use ADO to compress or repair MS access files in Access?
Topic Address: Http://access911.net/index.asp?board=4&recordid=71FAB71E


Problem:

How do you use ADO to compress or repair Microsoft access files in Access?




Reply:


When you used DAO, Microsoft provided CompactDatabase method to compress Microsoft Access files and RepairDatabase method to repair damaged Microsoft Access files. But since ADO came out, it seems like you forgot to provide the ability to compress and repair Microsoft Access files.


Now that Microsoft has found this problem, it also provides a workaround, but there are limitations on the version! The restrictions are described below:

ActiveX Data Objects (ADO), version 2.1
Microsoft OLE DB Provider for Jet, version 4.0
This is the extended feature of ADO that Microsoft has proposed: Microsoft Jet OLE DB Provider and Replication Objects (JRO)

This feature was first presented in JET OLE DB Provider version 4.0 (Msjetoledb40.dll) and JRO version 2.1 (Msjro.dll)!
These necessary DLL files are available after you install MDAC 2.1, and you can download the latest version of MDAC in the following pages!

Universal Data Access Web Site

Check with the VBE interface before downloading, and Microsoft Jet and Replication Objects x.x Library in references if it is already over 2.1, you can download it!

After you install MDAC 2.1 or more, you can use ADO to compress or repair a Microsoft Access file, and the following steps tell you how to compress a Microsoft Access file by using CompactDatabase method:

1, create a new form, select "Reference" in VBE.
2. Join Microsoft Jet and Replication Objects x.x Library (x.x is greater than or equal to 2.1).
3, in the appropriate place to add the following program code, remember to modify the data source content and the purpose of the file path:

Dim JRO as JRO. JetEngine
Set JRO = New JRO. JetEngine
Jro.compactdatabase "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\nwind2.mdb", _ ' source file
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\abbc2.mdb; Jet oledb:engine type=4 "' Destination file

After DAO 3.60, RepairDatabase method is no longer available, and the above program code shows the use of ADO CompactDatabase method, and it replaces DAO 3.5 RepairDatabase met hod!







Note:


1, error prompted (cannot perform this operation; This version of the feature is not available in a lower version of the database.) Because the version number does not match your database format, please see the table below


Engine version number
Jet Oledb:engine Type-> jet x.x Format MDB Files
1-> JET10
2-> JET11
3-> jet2x
4-> jet3x
5-> jet4x

2, other compression repair of the database objects and methods:
http://support.microsoft.com/default.aspx?scid=kb;zh-cn;240434
Although some corrupted databases can sometimes be successfully opened, data access is much slower because indexes or table rows are corrupted. You can run the repair and compression database utility in the Microsoft Access development environment to repair a corrupted database. When programming, you can use the CompactDatabase method of the Jet and Replication Objects (JRO), the Ijetcompact::compact method of the jet OLE DB provider, or the Data Access obje The Cdaodatabase::compactdatabase method of the CTS (DAO) to achieve this purpose.








Method Two:

Delphi code (not validated)
Uses Comobj,activex
Const
sConnectionString = ' Provider=Microsoft.Jet.OLEDB.4.0;Data source=%s; '
+ ' Jet oledb:database password=%s; ';


function Gettemppathfilename (): string;
Var
Spath,sfile:array [0..254] of char;
Begin
GetTempPath (254,spath);
GetTempFileName (spath, ' ~sm ', 0,sfile);
Result:=sfile;
DeleteFile (result);
End

function CompactDatabase (afilename,apassword:string): boolean;
compressing and repairing databases, overwriting source files
Var
stempfilename:string;
Vje:olevariant;
Begin
Stempfilename:=gettemppathfilename;
Try
Vje:=createoleobject (' JRO. JetEngine ');
Vje.compactdatabase (Format (Sconnectionstring,[afilename,apassword]),
Format (Sconnectionstring,[stempfilename,apassword]));
Result:=copyfile (Pchar (sTempFilename), Pchar (Afilename), false);
DeleteFile (sTempFilename);
Except
Result:=false;
End
End









Method Three:


VC Please refer to:
http://support.microsoft.com/default.aspx?scid=kb; en-us;230496
http://support.microsoft.com/?id=230501




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.