简体   繁体   中英

Encrypted SQLite database can't be opened with System.Data.SQLite

My SQLite Connection string looks like:

        string conn = "Data Source=" + filename + ";Version=3;";
        if (passphrase != null)
        {
            conn += "Page Size=1024;Password=" + passphrase + "";
        }

        _mDbConnection = new SQLiteConnection(conn);
        _mDbConnection.Open();

This works so far and the password is obviously correct. ;-) But whenever i want to run a query then i get the error:

SQLite error (26): file is not a database
Exception thrown: 'System.Data.SQLite.SQLiteException' in System.Data.SQLite.dll
System.Transactions Critical: 0 : <TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Critical"><TraceIdentifier>http://msdn.microsoft.com/TraceCodes/System/ActivityTracing/2004/07/Reliability/Exception/Unhandled</TraceIdentifier><Description>Unhandled exception</Description><AppDomain>dbtool.exe</AppDomain><Exception><ExceptionType>System.Data.SQLite.SQLiteException, System.Data.SQLite, Version=1.0.106.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139</ExceptionType><Message>file is not a database
file is not a database</Message><StackTrace>   at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String&amp;amp; strRemain)
   at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
   at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
   at System.Data.SQLite.SQLiteDataReader.NextResult()
   at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
   at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
   at System.Data.SQLite.SQLiteCommand.ExecuteReader()

The encrypted database file can however be openend fine with other tools like DB Browser for SQLite . The unencrypted version also works fine with System.Data.SQLite.

The SQLite Encryption Extension encrypts the entire database. That includes all headers, data definitions and anything else. A database encrypted this way is completely jibberish unless you are using the SQLite Encryption Extension. Otherwise, I would expect an error saying the database is not recognized as a database.

So, I'm not familiar with DB Browser for SQLite , but if it is using that extension to encrypt the database, you will only be able to read the database if you are using the SQLite Encryption Extension.

Since the extension costs about $2,000, it's a fair assumption that System.Data.SQLite is not working with this extension.

You will need this extension to read and write encrypted databases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM