When a VistaDB database has an encryption key set all of the contents are encrypted - both data and schema. The encryption key has to be specified as part of the connection information to open it. If an incorrect key is provided an exception is thrown when the database is opened. To separate this issue from other potential problems, 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) { try { using (VistaDBConnection dbconn = new VistaDBConnection("Data Source=C:\\test.vdb6;Password=WRONG")) { dbconn.Open(); // 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() Try Using dbconn As VistaDBConnection = New VistaDBConnection("Data Source=C:\\test.vdb6;Password=WRONG") dbconn.Open() ' 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") Else Console.WriteLine(ex.ToString()) End If End Try End Sub End Module |