2015-05-26 49 views
1

我已經使用nuget安裝sqlite-netSystem.Data.SQLite (x86/x64)。我已重建,我已重新啓動,我仍然收到以下錯誤:Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E)。這是觸發它的線:C#sqlite無法加載sqlite3.dll

db = new SQLiteConnection("Data Source=C:\\Users\\xxxxxxx\\Desktop\\mydb.sqlite;Version=3;"); 

我錯過了什麼嗎?這不應該工作嗎?

+0

該DLL文件是否存在於EXE目錄中? – SLaks

+0

沒有sqlite3.dll但存在System.Data.SQLite.dll。 –

+0

我只是重命名它或什麼? –

回答

2

我認爲它可能是你的應用程序和sqlite驅動程序之間的架構不匹配。

在此處下載與您的體系結構相匹配的預編譯的二進制包http://sqlite.org/download.html,並將.dll放入bin \ Debug或bin \ Release文件夾中。我認爲它可能是x86和x64之間的架構不匹配。

從文檔,你可以看到所需的部署結構:

<bin>\App.exe (optional, managed-only application executable assembly) 
<bin>\App.dll (optional, managed-only application library assembly) 
<bin>\System.Data.SQLite.dll (required, managed-only core assembly) 
<bin>\System.Data.SQLite.Linq.dll (optional, managed-only LINQ assembly) 
<bin>\System.Data.SQLite.EF6.dll (optional, managed-only EF6 assembly) 
<bin>\x86\SQLite.Interop.dll (required, x86 native interop assembly) 
<bin>\x64\SQLite.Interop.dll (required, x64 native interop assembly) 
2

您已經安裝了兩個不同的方式來談論從C#中不完全兼容的SQLite:各地土特產「sqlite3的薄的sqlite-Net組件.dll「程序集和用於SQLite的」System.Data.SQLite「全功能.NET數據提供程序。

sqlite-net只是將一些源文件添加到您的項目(SQLite.cs和SQLiteAsync.cs)。這裏面,你會看到很多extern的聲明是這樣的:

[DllImport("sqlite3" , EntryPoint = "sqlite3_open_v2", CallingConvention=CallingConvention.Cdecl)] 
public static extern Result Open ([MarshalAs(UnmanagedType.LPStr)] string filename, out IntPtr db, int flags, IntPtr zvfs); 

源碼網假定有一個在你的輸出目錄名爲「sqlite3.dll」文件。雖然文件「System.Data.SQLite.dll」實際上是一個與「sqlite3.dll」兼容的混合程序集,但安裝System.Data.SQLite程序包不會爲您提供此文件。

所以,你有兩個選擇:

  1. 下載從http://www.sqlite.org/download.html

  2. 的sqlite3.dll本地庫
  3. 查找了現在你的項目的一部分sqlite的淨源文件中的所有引用,從

    [DllImport("sqlite3", ... 
    

    改變他們

    [DllImport("System.Data.SQLite.dll", ... 
    

這可能是一個好主意,挑兩種方法(源碼網或System.Data.SQLite)之一,並卸載其他包(都有優點和缺點)。

+0

在這裏的正確答案,不知道爲什麼這會得到downvoted – MOnsDaR