SQLite Encryption - errorcode 21 (library routine called out of sequence)

Hi there,

I’ve an existing sqlite database created with an encryption key.
Database was created using Navicat and I can access/manage the database using Navicat and the given encryption key.
SQLite database is version 3.7.17

I’m using this db in a desktop app (Xojo 2013r4.1), running on my Mac OSX 10.9.2

The Connect method is giving an error 21 (library routine called out of sequence)

I’m used to SQLite but it’s my first encrypted db.
The code below was copied from documentation and I don’t understand what’s wrong.

Any help welcome !

[code] Dim dbFile As FolderItem
dbFile = GetFolderItem(“config.sqlite”)
If dbFile.Exists Then
Dim configDB As New SQLiteDatabase
configDB.DatabaseFile = dbFile
configDB.EncryptionKey = “*****”

If configDB.Connect Then
  ' some processing here
  MsgBox("Error reading config.sqlite: " + configDB.ErrorMessage + " (ErrorCode=" + str(configDB.ErrorCode))   
End If

MsgBox(“Config.sqlite not found”)
End if


Are you able to open the DB with an other program (SQLiteManager) ?
I createt a DB with Nacicat (encrypted).
I couldn’t open it with SQLiteManager.
I created a DB with SQLite (encrypted).
I couldn’t open it with Navicat.
I can open it with Xojo.

So it seems to me that Navicat Encryption is the problem.

Hi Stefan,

I did as you suggested, creating the SQLite db with SQLiteManager and it works fine in Xojo.
However, as you mentioned I can’t open the db with Navicat.

I’ll have to see if I can convert (or upload data) from Navicat db to SQLiteManager db because it’s an existing file which is used by other app (not Xojo).

Thanks anyway, you saved my day !


Since you are new to using encrypted SQLite databases, you may not have noticed but the ErrorCode is incorrect also. You should have gotten a ErrorCode 26 (File is encrypted or is not a database ) not ErrorCode 21. This is one of MANY bugs that have been reported and still unresolved for quite some time. If you stick with Xojo, I’m sure you’ll get very used to having to workaround such issues.