无法加载sqlite3.dll

本文关键字:dll sqlite3 加载 | 更新日期: 2023-09-27 17:50:47

我已经使用nuget安装了sqlite-netSystem.Data.SQLite (x86/x64)。我已经重建并重新启动,我仍然得到以下错误: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;");

我错过了什么吗?这难道不应该奏效吗?

无法加载sqlite3.dll

您已经安装了两种不完全兼容的从c#与SQLite通信的不同方式:围绕本地"sqlite3.dll"程序集的thin SQLite -net包装器,以及"System.Data. dll"。

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

sqlite-net假定在您的输出目录中有一个名为"sqlite3.dll"的文件。安装System.Data.SQLite包不会给你这个文件,尽管文件"System.Data.SQLite.dll"实际上是一个与"sqlite3.dll"兼容的混合程序集。

你有两个选择:

  1. 从http://www.sqlite.org/download.html下载sqlite3.dll原生库

  2. 找到sqlite-net源文件中现在是项目一部分的所有引用,并从

    更改它们
    [DllImport("sqlite3", ...
    

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

选择两种方法中的一种(sqlite-net或System.Data.SQLite)并卸载另一个包(两者各有利弊)可能是一个好主意。

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