From Xojo Documentation

Revision as of 17:09, 7 January 2022 by PLefebvre (talk | contribs) (Notes: Changed CreateDatabaseFile (deprecated) to CreateDatabase)
You are currently browsing the old Xojo documentation site. Please visit the new Xojo documentation site!

Property (As String )
aSQLiteDatabase.EncryptionKey = newStringValue
StringValue = aSQLiteDatabase.EncryptionKey

Supported for all project types and targets.

Specifies the encryption key used to create or connect to an encrypted database.


You cannot encrypt a database from within a transaction. You must encrypt it outside of any transactions.

To encrypt a new database, specify this value before calling CreateDataBase.

To connect to an encrypted database, specify this value before calling Database.Connect.

To encrypt an existing database, use the Encrypt method.

2017r3 and prior: AES-128 encryption is always used.

2018r1 and later defaults to AES-128, but AES-256 can also be used by including the prefix "aes256:" before the rest of the encryption key.

Sample Code

This code supplies EncryptionKey before attempting to connect to an encrypted database:

Var dbFile As New FolderItem("MyDB.sqlite")

Var db As New SQLiteDatabase
db.DatabaseFile = dbFile

db.EncryptionKey = "horse+20$"

// Key was correct; DB is connected
MessageBox("Connected to database.")
Catch error As DatabaseException
// Connection error. This could be because the key is wrong or other reasons
MessageBox("Connection error: " + error.Message)
End Try