![](/img/trans.png)
[英]Encrypted SQLite database can't be opened with System.Data.SQLite
[英]System.Data.SQLite Can't Load Extension
我正在嘗試在設置連接時加載新的json1擴展,但我一直收到此錯誤:
SQL邏輯錯誤或缺少數據庫
找不到指定的過程。
這是我的代碼:
SQLiteConnection connection = (SQLiteConnection)session.Connection;
connection.EnableExtensions(true);
Assembly assembly = Assembly.Load("System.Data.SQLite");
connection.LoadExtension(assembly.Location, "sqlite3_json_init");
我正在使用NHibernate,所以我只是在執行任何邏輯之前從會話中獲取連接。
有什么我做錯了嗎? 我也嘗試加載SQLite.Interop.dll,然后調用sqlite3_json_init
方法,但仍然無法正常工作。
我做了這個,它似乎仍然沒有工作:
SQLiteConnection connection = (SQLiteConnection)session.Connection;
connection.EnableExtensions(true);
string path = "F:\\GitHub\\ExampleProj\\lib\\sqlite\\SQLite.Interop.dll";
if (File.Exists(path))
{
connection.LoadExtension(path,
"sqlite3_json_init");
}
從SQLite.Interop.dll加載擴展是正確的方法。 所以你應該能夠做到以下幾點:
connection.EnableExtensions(true);
connection.LoadExtension(@"full\path\to\SQLite.Interop.dll", "sqlite3_json_init");
我已經測試了它並且它正在工作,所以如果你仍有問題,你可能需要說明你是如何獲得互操作文件的路徑的。 出於調試目的,可能在LoadExtension之前添加一個斷言,以確保您嘗試加載的互操作文件實際存在於您認為的位置。
還要確保你正在加載正確的版本(x86與x64。)如果你嘗試了錯誤的版本,你會得到,“找不到指定的模塊。” 在LoadExtension調用,即使它實際上在那里。
它實際上看起來你不需要輸入interop文件的完整路徑..顯然它確定你正在使用哪個處理器架構並在bin文件夾中找到SQLite.Interop.dll文件(bin / x64 / SQLite.Interop.dll)。 我只需要給它interop文件的名稱,它工作:
SQLiteConnection connection = (SQLiteConnection)sender;
connection.EnableExtensions(true);
connection.LoadExtension("SQLite.Interop.dll", "sqlite3_json_init");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.