2015-05-26 43 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