簡體   English   中英

無法使用System.Data.SQLite打開加密的SQLite數據庫

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

我的SQLite連接字符串如下所示:

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

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

到目前為止,該方法仍然有效,並且密碼顯然是正確的。 ;-)但是,每當我想運行查詢時,我都會收到錯誤消息:

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()

但是,可以使用其他工具(例如DB Browser for SQLite加密的數據庫文件DB Browser for SQLite 未加密的版本也可以與System.Data.SQLite一起正常使用。

SQLite加密擴展對整個數據庫進行加密。 這包括所有標題,數據定義和其他內容。 除非您使用的是SQLite加密擴展,否則用這種方法加密的數據庫完全是毫無用處的。 否則,我會期望一個錯誤,指出該數據庫未被識別為數據庫。

因此,我對SQLite的數據庫瀏覽器並不熟悉,但是如果它使用該擴展名對數據庫進行加密,則只有在使用SQLite加密擴展名時,您才能讀取數據庫。

由於該擴展的成本約為2,000美元,因此可以合理地假設System.Data.SQLite無法使用此擴展。

您將需要此擴展名來讀寫加密的數據庫。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM