Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite unable to open database file is encrypted or is not a database?

I am working on a windows application .net 2.0 with sqlite database, my connection string stays in app.config like

<connectionStrings>
<add name="SQLiteDB" 
     connectionString="Data Source=|DataDirectory|database.s3db;version=3;password=mypassword;" 
     providerName="System.Data.Sqlite"/>
</connectionStrings>

In the connection string i have defined password as "mypassword" if i remove this password everything is working well but when i use password clause, it gives me error in connection.open() syntax that

File opened that is not a database file
file is encrypted or is not a database

I searched on net and found some version issue but i am using version 3 only as i stated in connection string i also tried removing the "version=3" but problem remains the same.

I am doing this first time, what is the solution of it?

like image 271
Mogli Avatar asked Apr 16 '13 06:04

Mogli


People also ask

How do I open an encrypted database in SQLite?

Right-click on your db file in its folder and select "open with..." then select the exe for SQLite2009 Pro, or drag the file onto the exe (assuming you're on Windows), or pass the file path to the exe via the cmd line.

Why SQLite Cannot open database file?

If SQLite is unable to open the database file, this means that the SQLite database you are trying to open is corrupted. There are various causes of corruption, such as file overwrite issues, file locking issues, database synchronization failures, storage media failures, and many more.

How do you check if SQLite database is encrypted?

Inspect the first 16 bytes of the database file directly, if they are equal to the string "SQLite format 3\000" then the file is not encrypted, and is a standard SQLite database. If something happens and a crash occurs during sqlcipher_export, the original database will be left untouched.

Is SQLite database encrypted?

SQLite doesn't support encrypting database files by default. Instead, you need to use a modified version of SQLite like SEE, SQLCipher, SQLiteCrypt, or wxSQLite3.


1 Answers

When you specify a password in the connection string, and the database already exists, SQLite assumes the database is encrypted and will try to decrypt it with said password. If you haven't set a password on the database yet, this will result in the "file is encrypted" error, because the supplied password can't be used to decrypt an unencrypted database.

You can either delete the database, and SQLite will create a new encrypted database using the password in the connection string. Or, you can encrypt your existing database using the ChangePassword() method:

// Opens an unencrypted database    
SQLiteConnection cnn = new SQLiteConnection("Data Source=c:\\test.db3");    
cnn.Open();    

// Encrypts the database. The connection remains valid and usable afterwards.    
cnn.ChangePassword("mypassword");

Reference: Encrypting, decrypting and attaching to encrypted databases

like image 115
2Toad Avatar answered Sep 17 '22 18:09

2Toad