How do I use ADO to compress or fix MS Access files in Access?
Topic address: http://access911.net/index.asp? Board = 4 & recordid = 71fAb71e problem:
How to use ADO to compress or fix Microsoft Access files in Access?
Reply:
When you use DAO before, Microsoft has a CompactDatabase Method to compress Microsoft Access files, RepairdAbase Method to repair corrupted Microsoft Access files. However, since ADO came out, it seems to have forgot to provide relative compression and repair the Microsoft Access file. Now Microsoft discovers this problem, and also provides a solution, but there is a version limited! Restrictions are as follows: ActiveX Data Objects (ADO), Version 2.1Microsoft Ole DB Provider for Jet, Version 4.0 This is the extension of Ado proposed by Microsoft: Microsoft Jet Ole DB Provider and Replication Objects (jro) This feature is in Jet Ole DB Provider Version 4.0 (MSJETOLEDB40.DLL) and JRO VERSION 2.1 (MSJRO.DLL) were first proposed! These necessary DLL files are there after you have installed MDAC 2.1, you can download the latest version of MDAC in the following web pages! Universal Data Access Web Site Checks it in the VBE interface before downloading, [Reference] MICROSOFT JET and Replication Objects X.x Library if it is already 2.1 or more, you can download it! Once you have installed the MDAC 2.1 or more, you can use ADO to compress or fix Microsoft Access files. Here: How do you use CompactDatabase Method to compress Microsoft Access files: 1, create a new form, select VBE [Quote]. 2. Add Microsoft Jet and Replication Objects X.x Library, where (X.x is greater than or equal to 2.1). 3, add the following program code in the appropriate place, remember to modify the contents of the Data Source and the path to the local file:
Dim Jro As Jro.jetengineset Jro = New Jro.jetengineJro.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 "'After DAO 3.60, the RepairdAbase method has not been used, and the above program code shows the usage of ADO CompactDatabase Method, and it also replaces it REPAIRDATABASE METHOD at Dao 3.5!
Note:
1. An error message appears (this operation cannot be performed; this version of this version is not available in a low version of the database.) Is because the version number does not match your database format, please see the following comparative table engine version number Jet OLEDB: ENGINE TYPE -> JET XX Format MDB Files 1 -> JET10 2 -> JET11 3 -> Jet2x 4 -> Jet3x 5 -> Jet4x 2, other compressed repair database objects and methods: http://support.microsoft.com/ DEFAULT.ASPX? SCID = KB; EN; EN; 240434 Although some damaged databases can sometimes open, due to indexing or table lines, data access speed is much slower. You can repair the corrupted database in the Microsoft Access development environment. When programming, you can use Jet and Replication Objects (JRO) CompactDatabase method, Jet OLE DB provider's iJetCompact :: Compact :: CompactDatabase :: CompactDatabase :: CompactDatabase method for Data Access Objects (DAO).
Method Two:
Delphi code (not verified)
// uses ComObj, ActiveXconst 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; // compression and repair the database, covering the source file 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;
Method 3:
VC Please refer: http://support.microsoft.com/default.aspx? Scid = kb; EN-US; 230496HTTP: //support.microsoft.com/?id = 230501