VistaDB 5
Gibraltar VistaDB > Developer's Guide > How To Perform Common Tasks > How To - Check for a Bad Encryption Key (Password) at Load Time
How To - Check for a Bad Encryption Key (Password) at Load Time

Working with an Encrypted Database

Remember that setting an Encryption Key on a VistaDB database is not the same thing as putting a password on an Access file. The encryption key is used to encrypt every block on disk with VistaDB. This can lead to a 30% or more performance slowdown due to every page having to be encrypted and decrypted when it is loaded or written to disk. User level access control passwords are application logic that you should implement in your Application. The database engine does not handle user access control concepts.

Loading a database with the wrong password set will cause an Exception to be generated.

Catch the exception and look for error 116 (VistaDB.Diagnostic.Errors.dda_EncryptionKeyInvalid) in the exception list.

The following C# and VB.NET example demonstrates how to do this.

Checking Encryption Key
Copy Code
using System;
using VistaDB;
using VistaDB.Provider;

namespace OpenEncrypted
    class Program
        static void Main(string[] args)
                using (VistaDBConnection dbconn = new VistaDBConnection("Data Source=C:\\test.vdb4;Password=WRONG"))


                    // Do something here

            catch (VistaDB.Diagnostic.VistaDBException ex)
                // You could also check for the value 116 here
               if( ex.Contains(VistaDB.Diagnostic.Errors.dda_EncryptionKeyInvalid))
                    Console.WriteLine("BAD Encryption Key Given");
Checking Encryption Key
Copy Code
Imports VistaDB
Imports VistaDB.Provider

Module Module1

    Sub Main()


            Using dbconn As VistaDBConnection = New VistaDBConnection("Data Source=C:\\test.vdb4;Password=WRONG")


                ' DO something here
            End Using

        Catch ex As VistaDB.Diagnostic.VistaDBException

            ' You could also just look for 116 here
            If ex.Contains(VistaDB.Diagnostic.Errors.dda_EncryptionKeyInvalid) Then
                Console.WriteLine("ERROR: Bad Encryption Key given")
            End If

        End Try

    End Sub

End Module 
See Also