Data | database | compression
MDB Database compression method
Jimzj@21cn.com
Although the MDB database function is not very powerful, but because there is already a default driver in the win X system, there is no need to install a management drive like Sql,sybase, and it is easy to carry, and many small applications or Web sites use MDB databases. Often manipulate the MDB data, you will often encounter to compress the data, the following I found on the Internet and their use of experience to write about in various environments compressed MDB database methods, provide you with reference:
One, ASP or VB in the compression
When using DAO, Microsoft provides CompactDatabase method to compress Microsoft Access repositories, RepairDatabase method to repair damaged Microsoft Access repositories 。 But since ADO came out, but also provided a solution, but there is a version of the restrictions! The restrictions are described below:
ActiveX Data Objects (ADO), version 2.1
Microsoft OLE DB Provider for Jet, version 4.0
This is the extension of ADO that Microsoft has proposed: Microsoft Jet OLE DB Provider and Replication Objects (JRO) in Jet OLE DB Provider version 4. 0 (Msjetoledb40.dll) and JRO version 2.1 (Msjro.dll) were presented for the first time! These necessary DLL files are available after you have MDAC 2.1 installed, and you can download the latest version of MDAC on the following pages! Universal Data Access Web site Check in VB6 before downloading, and Microsoft Jet and Replication Objects x.x library in Project Settings reference project if it is already 2.1 The above version, you can not download it! After you have installed MDAC version 2.1 or more, you can use ADO to compress or repair the Microsoft Access repository, and the following steps tell you how to compress Microsoft Access data using CompactDatabase method Library: 1, open a new project, click "Project" "Set Reference project" in the function table.
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 code, remember to modify the contents of data source and target database 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 database
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\abbc2.mdb; Jet oledb:engine type=4 "' Destination database
After DAO 3.60, RepairDatabase method is no longer available, and the above code shows the use of ADO CompactDatabase method, and it replaces the DAO 3.5 repairdatabase Meth Od
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
Three, C + + Builder in compression
C + + in the Internet does not find a good method, but according to my original database method to build MDB, also found a relatively practical compression method;
2, by Ole thought of the function to achieve the actual pressure function
#include <ComObj.hpp>
void CompactDatabase (String stfilename)
{
Variant vcreateaccess;
Procedure pcreateaccess ("CompactDatabase");
String sttempfile = "Temp.mdb";
if (FileExists (sttempfile)) DeleteFile (sttempfile);
Pcreateaccess << "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Stfilename + ";"; If there is a password please add the following line of Jet Oledb:database Password=password; ";
Pcreateaccess << "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Sttempfile + ";"; If there is a password please add the following line of Jet Oledb:database Password=password; ";
#import "C:\PROGRAM Files\Common FILES Ystem\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:
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.