Error: file is not a database when using .open

My encrypted db can successfully be accessed by launching sqpcipher mydb.db and setting the key. However, when I first launch sqlcipher, doing .open mydb.db will cause to raise an Error: file is not a database after every statement.

The sqlcipher version is 4.4.2 (Community edition) without any mismatch between the version used to create the database and the version used to access it.

What’s wrong here?

Thanks in advance.

Hi @anphetamina

You need to supply the key after you use the .open command within the SQLCipher shell. For example on a SQLCipher-encrypted database:

$ ./sqlcipher
sqlite> .open foo.db
sqlite> PRAGMA key = 'foo';
sqlite> SELECT * FROM t1;

Are you doing this?

Exactly, I even tried setting the key prior the .open

Hi @anphetamina

What is printed within your shell when you execute the following command:

PRAGMA cipher_version;

sqlite> PRAGMA cipher_version;
4.4.2 community

@anphetamina This appears to work as expected for me with the latest release version

$ ./sqlcipher
SQLite version 3.34.1 2021-01-20 14:10:07 (SQLCipher 4.4.3 community)
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open test.db
sqlite> pragma key = 'test';
ok
sqlite> .schema
CREATE TABLE t1(a,b);
sqlite> select * from t1;
1|2