Compress Access database _php tutorial in VB

Source: Internet
Author: User
Tags access database
If you delete data or objects in an Access database, an Access project, you can create fragmentation and reduce the efficiency of disk space usage. At the same time, the size of the database file does not decrease, but increases continuously until your hard disk has no space. Is there a good way to deal with it? In fact, you can compress the database in access to improve the performance of your Access database and Access project, which is essentially copying the file and re-organizing how the file is stored on disk. However, such compression in an Access project does not affect database objects, such as tables or views, because they are stored in a Microsoft SQL server database and not in the Access project itself. Similarly, this compression does not affect the automatic numbering in an Access project. In an Access database, if a record has been deleted from the end of the table, the auto-numbering value is reset when the database is compacted. The AutoNumber value of the next record added will be higher than the automatic numbering value for the last record that is not deleted in the table.
Here is how to use a compactjetdatabase process in VB to achieve the compression of Access database files, in this process has an optional parameter, is whether you need to back up the original database files to a temporary directory (true or FALSE) before compression. I use this method to compress the 21.6MB database to just 300KB.
' This code can be placed in a module and used in other forms as well
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) Then
' Perform backup if backup is required
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 database files via DBEngine
Dbengine.compactdatabase location, Strtempfile
' Delete the original database file
Kill Location
' Copy has just compressed the temporary database file to its original location
FileCopy Strtempfile, location

http://www.bkjia.com/PHPjc/631184.html www.bkjia.com true http://www.bkjia.com/PHPjc/631184.html techarticle If you delete data or objects in an Access database, an Access project, you can create fragmentation and reduce the efficiency of disk space usage. 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.