Previous Page

Encrypting a Database

If you want to protect your secured database from unauthorized access by someone using a disk editor or other utility program, you can encrypt it. Encryption makes a database indecipherable, which protects it from unauthorized viewing or use, particularly during electronic transmission or when it's stored on floppy disk, tape, or compact disc. Encrypting an unsecured database will have no effect because anybody can open the database with Microsoft Access or Visual Basic and gain full access to all objects in the database.

The User-Level Security Wizard automatically encrypts your database. You can encrypt or decrypt a database by starting Microsoft Access without opening a database, and then using the Encrypt/Decrypt Database command (Tools menu, Security submenu). You can also use the CompactDatabase method of the DBEngine object to encrypt or decrypt a database. For example, the following procedure creates an encrypted version of the Orders sample database named Eorders:

Sub EncryptDb()
   Const conFilePath = "C:\Program Files\Microsoft Office\Office\Samples\"
   DBEngine.CompactDatabase conFilePath & "Orders.mdb", conFilePath & _
      "EOrders.mdb", dbLangGeneral, dbEncrypt
End Sub

When you encrypt a database using the same file name as that of the original database, Microsoft Access deletes the original unencrypted file if the encryption process is successful. If an error occurs, Microsoft Access doesn't delete the original file.

Note   Encrypting a database slows its performance by up to 15 percent. Also, an encrypted database cannot be compressed by programs such as DriveSpace or PKZIP. If you try to compress an encrypted database, its size doesn't change.

© 1996 Microsoft Corporation. All rights reserved. Next Page


Casa de Bender