Home > Backend Development > PHP Tutorial > Compress ACCESS database in VB_PHP tutorial

Compress ACCESS database in VB_PHP tutorial

WBOY
Release: 2016-07-13 17:01:11
Original
1022 people have browsed it

If you delete data or objects in an Access database or Access project, fragmentation may occur and reduce disk space usage efficiency. At the same time, the size of the database file does not decrease, but continues to increase until your hard drive runs out of space. Is there any good way to deal with it? In fact, database compression can be optimized in Access to improve the performance of Access databases and Access projects. The essence of such compression processing is to copy the file and reorganize the way the file is stored on the disk. However, such compression in an Access project does not affect database objects (such as tables or views) because they are stored in the Microsoft SQL Server database and not in the Access project itself. Likewise, such compression will not affect automatic numbering in Access projects. In an Access database, if records have been deleted from the end of the table, compressing the database will reset the autonumbering value. The autonumber value of the next record added will be one greater than the autonumber value of the last record in the table that was not deleted.
The following describes how to use a CompactJetDatabase process in VB to compress Access database files. There is an optional parameter in this process, which is whether you need to back up the original database files to a temporary directory before compression ( True or False). I used this method to compress a 21.6MB database to just 300KB.
'These codes can be placed in modules and used in other forms
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
'Check if the database file exists
If Len(Dir(Location)) Then
'If a backup is needed, perform a backup
If BackupOriginal = True Then
strBackupFile = GetTemporaryPath & "backup.mdb"
If Len(Dir(strBackupFile)) Then Kill strBackupFile
FileCopy Location, strBackupFile
End If
'Create temporary file name
strTempFile = GetTemporaryPath & "temp.mdb"
If Len( Dir(strTempFile)) Then Kill strTempFile
'Compress the database file through DBEngine
DBEngine.CompactDatabase Location, strTempFile
'Delete the original database file
Kill Location
'Copy the temporary database that has just been compressed File to original location
FileCopy strTempFile, Location

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631184.htmlTechArticleIf you delete data or objects in an Access database or Access project, fragmentation may occur and cause disk space usage inefficiency of reduction. At the same time, the size of the database file has not been reduced,...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template