繁体   English   中英

C#sqlite无法加载sqlite3.dll

[英]C# sqlite Unable to load sqlite3.dll

我已经使用nuget安装sqlite-netSystem.Data.SQLite (x86/x64) 我已经重建,并且已经重新启动,但是仍然出现以下错误: Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E) Unable to load DLL 'sqlite3': The specified module could not be found. (Exception from HRESULT: 0x8007007E) 这是触发它的行:

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

我想念什么吗? 这不行吗?

我认为这可能是您的应用程序和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)

您已经安装了两种不完全兼容的从C#与SQLite进行通信的方式:围绕本机“ sqlite3.dll”程序集的瘦sqlite-net包装器,以及功能齐全的.NET数据提供程序“ System.Data.SQLite”。对于SQLite。

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

sqlite-net假定您的输出目录中有一个名为“ sqlite3.dll”的文件。 尽管文件“ System.Data.SQLite.dll”实际上是与“ sqlite3.dll”兼容的混合程序集,但安装System.Data.SQLite软件包不会提供此文件。

因此,您有两种选择:

  1. http://www.sqlite.org/download.html下载sqlite3.dll本机库

  2. 在现在成为项目一部分的sqlite-net源文件中找到所有引用,并从中进行更改

     [DllImport("sqlite3", ... 

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

最好选择两种方法之一(sqlite-net或System.Data.SQLite)并卸载另一种程序包(两者都有优缺点)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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