sqlite error code 26

Hi All.

Trying to out-think the users I have, I have created an encrypted database with one key (i.e. thisisthekey) and then tried to open it with ANOTHER key (i.e. thisISNTthekey). I expect this to fail. And it does. With an error code 26 which the sqlite reference says “isn’t a database”. But I know it is.

Why am I getting this?
Any ideas?


Because trying to open an encrypted SQLite DB without the proper key is like opening a garbage file.

Because in SQLite the database driver/library has no way to know if a given file is an encrypted database or not a database at all. SQLite’s method of database encryption is to completely encrypt the entire file, just like if you encrypted a text file. Without the correct encryption key (and encryption method), there’s no way to tell what kind of file it is. When you set the encryption key for connecting to a SQLite database, it unencrypts the file’s contents as it loads it into memory, again just like you would for an encrypted text file. So, without the correct encryption key, all the database driver can say is the file it attempted to open is not a valid database file.

Rick and Jay.

Makes sense… just wish the error message was something less cryptic.

I had someone ask me to use this program, which I developed for my use. The office has passwords left, right and center, and I can’t be bothered to remember them, but don’t want people rooting around in my stuff. I told the person they could try it, but if they forgot the password, everything was gone.

Let’s see if they listened…
(evil grin)


If you know the file you are attempting to open is really a SQLite database, then you can interpret the error to mean the encryption key is incorrect (or the file is damaged). If you let your user choose a file to open, then you have to tell the user that either the key is incorrect, or they didn’t choose an actual database file.

You should avoid encrypting a db file with a “forgetful” user password. Anyone who has administered any system, knows that their users will block themselves at some point and you must have some way of recovering their access again.