Compressing ACCESS database _ PHP in VB tutorial

Source: Internet
Author: User
Compress the ACCESS database in VB. If you delete data or objects in the Access database or Access project, fragments may occur and the disk space usage efficiency may be reduced. At the same time, the size of the database file is not reduced. if you delete data or objects in the Access database or Access project, fragments may occur and the disk space usage efficiency may be reduced. At the same time, the size of the database file is not reduced, but is constantly increasing until your hard disk has no space. Is there a good solution? In fact, the database can be compressed and 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 re-organize the storage of files on the disk. However, such compression in the Access Project does not affect database objects (such as tables or views), because they are stored in the Microsoft SQL Server database rather than in the Access project itself. Similarly, this compression will not affect the automatic number in the Access Project. In the Access database, if records have been deleted from the end of the table, compressing the database will reset the automatic number value. The automatic number of the next record to be added will be greater than the automatic number of the last record not deleted in the table.
The following describes how to use a CompactJetDatabase process in VB to compress Access database files. in this process, an optional parameter is provided, whether you need to back up the original database files to a temporary directory (True or False) before compression ). I used this method to compress a MB database to only KB.
'These codes can be placed in the module 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 whether the database file exists
If Len (Dir (Location) Then
'Back up if you need to back up
If BackupOriginal = True Then
StrBackupFile = GetTemporaryPath & "backup. mdb"
If Len (Dir (strBackupFile) Then Kill strBackupFile
FileCopy Location, strBackupFile
End If
'Create a temporary file name
StrTempFile = GetTemporaryPath & "temp. mdb"
If Len (Dir (strTempFile) Then Kill strTempFile
'Use DBEngine to compress database files
DBEngine. CompactDatabase Location, strTempFile
'Delete the original database file
Kill Location
'Copy the temporary database file that has just been compressed to the original location
FileCopy strTempFile, Location

Bytes. At the same time, the size of the database file is not reduced ,...

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.