VistaDB 6
VistaDB / Developer's Guide / How To Perform Common Tasks / How To - Pack a Database
In This Topic
    How To - Pack a Database
    In This Topic

    Why pack your database?

    The database file can become fragmented with free space due to additions and deletions over the course of an application lifetime. This is normal and to be expected. Periodically you should pack the database to compress free space and reorganize the internal layout of the database on disk.  There are no broad rules of thumb for this, it really depends upon your application.  You should definitely decide on a maintenance strategy for your application and build it into the application as early as possible.

    Pack to change your password on a database

    Why do you have to pack the database when you change the password? The entire database is encrypted when you put a password on the database. This is not a simple access password to prevent people from loading it in the DataBuilder. The password is used as the basis for an encryption key so if you change the password, all the data in that database must be decrypted and then encrypted again using the new key.

    Visual Feedback to the user

    You may optionally set the Gauge hook to display a progress indicator while the database is being packed. This is highly recommended for user GUI based apps where a user may think your application has crashed if it stops responding for a long period of time.

    Backup your database at the same time

    You may also specify a backup flag if you want the database to be backed up prior to packing. The backup file will be named the same as the original database, but with a .backupCopy appended to the end of the filename. If the file exists it will be overwritten.

    Changes the options in the database

    If you want to change the options of the database (PageSize, LCID, case sensitivity) you will need to pack the database also. Any change that impacts the entire database headers or structures will always require a pack operation.

    Example

    The following code sample shows a simple version of the Pack operation - where no backup file is being made and no user feedback is being provided.

    IVistaDBDDA DDAObj = VistaDB.DDA.VistaDBEngine.Connections.OpenDDA();
    
    // Use a specific path on the drive
     DDAObj.PackDatabase(@"c:\test.vdb6");
    
    
    // Use the local working directory path where the EXE was launched
     DDAObj.PackDatabase(@"test.vdb6");
    
    Dim DDAObj As VistaDB.DDA.IVistaDBDDA DDAObj = VistaDB.DDA.VistaDBEngine.Connections.OpenDDA()
    
     // Use a specific path on the drive
     DDAObj.PackDatabase("C:\dest.vdb6")
    
     // Use the local working directory path where the EXE was launched
     DDAObj.PackDatabase("dest.vdb6")
    

    The database must NOT be open in another application in order for it to be packed. The file must be opened in Exclusive mode for pack to work correctly.

    Temp Files and Permissions

    All permissions on the file are kept during the pack process. A temporary file may be generated during the pack operation, but it is removed after the pack is complete.

    The path does not have to be hard coded into the pack command. Dot Net will look in your local path first, so if you have the database in the same location as the EXE you can simply put the database name as the parameter.

    Network Drive Packing

    It is not recommend that you pack a drive over a network.  Loss of connectivity to the network could cause a corruption of your database.

    See Also