怎样经由ADO来压缩Microsoft Access数据库

2016-01-29 18:29 42 1 收藏

怎样经由ADO来压缩Microsoft Access数据库,怎样经由ADO来压缩Microsoft Access数据库

【 tulaoshi.com - ASP 】

  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 be achieved by using the ADO extension: Microsoft Jet OLE DB Provider and Replication Objects (JRO). This capability was implemented for the first time in the JET OLE DB Provider version 4.0 (Msjetoledb40.dll) and JRO version 2.1 (Msjro.dll). These DLL files are available after the install of MDAC 2.1. You 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 be properly installed on the computer. 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
In 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 method 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, you can generate the wrapper classes more efficiently by using the no_implementation and 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 destination database paths) to the .cpp file where you
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 out, the
database is automatically upgraded to the 4.0 version (Jet OLEDB:Engine Type=5). See 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 see 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 : k

来源:http://www.tulaoshi.com/n/20160129/1505994.html

延伸阅读
问:我们公司统一使用Access数据库,并且通过e-mail的发送来同步数据,但我发现这些文件都非常巨大,而用ZIP压缩后又变得很小。我不知道这是怎样造成的?有没有更好的解决办法? 答:对于某些操作,Access分配硬盘空间时存在一些问题,比如不自动收回已用的空间,这样就造成文件很大,这可能就是你提到的问题的原因。你可以使用菜单...
标签: SQLServer
摘要:本文描述了将Access数据库转换到SQL Server 数据库的过程和工具 简介 随着用户对于企业级高性能数据库的需求的增长,用户时常要从Microsoft Access Jet引擎的文件-服务器环境下转换到 Microsoft SQL Server的客户-服务器环境。Microsoft Office 2000中的Access 2000 Upsizing Wizard可实现将数据表和 查询转移到SQL Server 7.0中。如...
本人最近正在进行呼叫中心的座席端和服务器软件开发,座席端登录部分是进行提取主机信息,然后使用SOCKET提交给远程服务器,服务器再在后台数据库中进行查找信息,进行对比,看是否允许座席端主机登录,因为我的电脑中无法安装SQLSERVER,所以 , 后台数据库暂时使用access小型数据库进行代替,到后期可以改为SQLSERVER数据库,,我在后台数据...
一、密码式 给数据库起一个随机复杂的名称,避免被猜到被下载,这种方式在以前很流行,因为大家都对自己的代码很有自信。但随着错误提示对数据库地址的泄露导致数据库被非法下载,这种方式也就越来越少人用了。 二、"#"式 在数据库名称里加上#号,从URL上请求时#是请求地址和请求参数的一个分隔字符,如果知道了数据库名...
问:我们单位财务以前用的Access是97版,前不久将Access 97升级至2000版本了。升级完成后出现问题,打开原有的文件后系统提示:“Access 2000无法识别旧版本的数据库文件”,请问有没有办法可以修复数据库? 答:你可以利用软件AccessFix(下载地址为http://www.onlinedown.net/soft/16220.htm)来修复数据库。安装完成后点击按钮“Add ...

经验教程

234

收藏

97
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部