我在asp之中看到了数据库压缩的代码,但是转到vb之后,就不行了,请问能实现吗?
谢谢
谢谢
解决方案 »
- 请问如何得到鼠标移动时,它下面控件的Name
- 怎么样判断当然窗体,是否有弹出的窗体.
- 求一个源代码
- (在線..)為什么將image框放大後圖像移動時會一閃一閃?
- 请高手进来!我打印的是msflexgrid表
- XP下VB6的函数和控件否与2000下一样,为何我的程序在XP下不正常?
- 天凌凌 地零零 请各位高手快显灵 thanks
- 连按两下ctrl呼出界面,这个怎么写
- 一个很菜的问题拉--------
- 如何用VB编启动是可以带参数的程序呢?(例如:我自定义了一种文件,双击用我的程序打开,程序自动会打开这个文档
- com 与com+加是有什么区别,用vb来写,重要区别在哪?
- 软件在没有VB的机子上运行提示".comdlg32.ocx不能正确注册 "??如何??
Compact and repair databases in ADOIn a previous tip (Compact and repair Jet databases with DAO), we showed you how to compact and repair a database with DAO. However, if you're using ADO, you can also compact and repair Access databases using Jet and Replication Objects (JRO).
To take advantage of JRO's CompactDatabase method, which will also repair the database, set a reference the JRO library, Microsoft Jet And Replication Objects 2.1 Library. Next, declare and set a JetEngine object variable, like so
Dim JRO As JRO.JetEngineSet JRO = New JRO.JetEngine
JRO.CompactDatabase _"Provider=Microsoft.Jet.OLEDB.4.0;" _& "Data Source=C:\myData1.mdb", _"Provider=Microsoft.Jet.OLEDB.4.0;" _& "Data Source=C:\myDataNewName.mdb"_& ";Jet OLEDB:Engine Type=4"
This command follows similar syntax as DAO's CompactDatabase method-you must provide the old database name and the new database name. In the case of JRO, however, you must also provide a valid connection string, as well as indicate the type of Jet engine to compact the database as. We used 4 to create a Jet Version 3.x database suitable for Access 97 users. If you work with Access 2000 use the value 5 to create a Jet Version 4.x database.
Compact and repair Jet databases with DAOIf you're like most developers, you've run into problems with Microsoft Access databases. Access' databases are typically reliable, but occasionally they can get damaged. There are numerous reasons why, such as powering down the computer without first closing the database file or the system simply crashing. Another source of problems for databases is excessive fragmentation-when records are deleted from a database file, the file becomes fragmented. Whatever the reason, once the database is damaged, end-users are often left stranded until technical support finds the time to help them. Fortunately, you can take measures to help users quickly recover from such problems, by providing built-in utilities that perform routine database maintenance.
The DAO library provides two methods to perform the necessary maintenance that keeps Access databases running smoothly--RepairDatabase and CompactDatabase. The RepairDatabase method uses the syntax
RepairDatabase dbname
where dbname is a string representing the full pathname of the Access database (.MDB) that you need to repair. This CompactDatabase method uses the following syntax:
CompactDatabase olddb, newdb, _locale, options, password
You specify the full path and filename of your source database as a string in the method's olddb property. Likewise, you specify the destination of the compacted database with the newdb property.
So, to use these statements, you could add code similar to:
RepairDatabase "C:\myData1.mdb"CompactDatabase "C:\myData1.mdb", App.Path & "\myDataNewName.mdb"
If you use DA0 3.6, then you can remove the RepairDatabase statement. DAO 3.0 incorporates this functionality into the CompactDatabase method-you can no longer compact and repair databases as separate actions.
下面介绍如何在VB中用一个CompactJetDatabase过程实现对Access数据库文件的压缩处理,在这个过程中有一个可选参数,就是在压缩前你是否需要把原有的数据库文件备份到临时目录(True或 False)。我用此办法使21.6MB的数据库压缩到仅仅300KB。
' 这些代码可放在模块中,在其他窗体也使用
Public Declare Function GetTempPath Lib "kernel32" Alias _
"GetTempPathA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Public Const MAX_PATH = 260
Public Sub CompactJetDatabase(Location As String, Optional BackupOriginal As Boolean = True)
On Error GoTo CompactErr
Dim strBackupFile As String
Dim strTempFile As String
'检查数据库文件是否存在
If Len(Dir(Location)) Then
' 如果需要备份就执行备份
If BackupOriginal = True Then
strBackupFile = GetTemporaryPath & "backup.mdb"
If Len(Dir(strBackupFile)) Then Kill strBackupFile
FileCopy Location, strBackupFile
End If ' 创建临时文件名
strTempFile = GetTemporaryPath & "temp.mdb"
If Len(Dir(strTempFile)) Then Kill strTempFile '通过DBEngine 压缩数据库文件
DBEngine.CompactDatabase Location, strTempFile ' 删除原来的数据库文件
Kill Location ' 拷贝刚刚压缩过临时数据库文件至原来位置
FileCopy strTempFile, Location