7

我在我的应用程序中添加了我认为必要的 SQLite(和 sqlite-net)包。但是,在运行它时,我遇到了一个异常:

System.DllNotFoundException 未被用户代码处理 HResult=-2146233052 消息=无法加载 DLL 'sqlite3':找不到指定的模块。(例外来自

我安装了以下 SQLite 包:

在此处输入图像描述

什么不见​​了?

更新

我尝试了ajawad987的建议,但仍然得到相同的运行时错误,即使我有这个:

在此处输入图像描述

...和这个:

在此处输入图像描述

更新 2

这个运行时异常发生的地方(在 SQLite.cs 中)对我来说似乎很奇怪:

如果银光 || USE_CSHARP_SQLITE

        var r = SQLite3.Open (databasePath, out handle, (int)openFlags, IntPtr.Zero);

别的

        // open using the byte[]
        // in the case where the path may include Unicode
        // force open to using UTF-8 using sqlite3_open_v2
        var databasePathAsBytes = GetNullTerminatedUtf8 (DatabasePath);
        var r = SQLite3.Open (databasePathAsBytes, out handle, (int) openFlags, IntPtr.Zero);

万一

但是我使用的是C#,那么为什么失败的行甚至还在运行呢?(它在“其他”块中失败)?

4

3 回答 3

15

Is your project build set to Any CPU? You'll need to set it to either x86 or x64 for SQLite3. The x86 route will yield more compatibility across devices, so I recommend that option unless your doing some specific 64-bit stuff.

Edit: You'll also need to download the actual Sqlite DLL manually from Sqlite's main site. The file you want is named sqlite-dll-win32-x86-3080702.zip. Extract the DLL from that ZIP and add it to your project as a content file. Set the copy to output directory option in the properties tool window to Copy Always, and rebuild. Also ensure that your project is set to the x86 option as mentioned above.

This should hopefully do the trick... its been a while since I've used Sqlite in a .NET application.

Side Notes: The Nuget package you downloaded actually only contains the C# wrapper library around the real Sqlite DLL.

于 2014-12-06T05:28:01.643 回答
3

我在 Windows 商店应用程序上遇到了同样的问题,我按照本教程解决了这个问题: http ://www.c-sharpcorner.com/UploadFile/d351ba/working-with-sqlite-in-windows-store-apps/

无需手动下载dll。重要的步骤是第五步:

5. 添加对项目的引用。

右键单击解决方案下对项目的引用,选择添加引用。这将打开项目的参考管理器。

在参考管理器中单击 Windows 版本。我的应用程序面向 Windows 8.1,因此我选择了“Windows 8.1”。从列表中选择扩展,如前面的屏幕截图所示。现在您将获得适用于您的项目的 SDK 列表。从屏幕上可以看出,SQLite for Windows Runtime (Windows 8.1) 在 NuGet Package Installer 的 SQLite 安装后列表中可用。

现在检查/勾选两个选项 Microsoft Visual C++ 2013 Runtime Package for Windows 8.1 和 SQLite for Windows Runtime (Windows 8.1),如屏幕截图所示。然后点击“确定”。

检查是否添加了引用。您可以看到添加了引用,但在这些添加的引用上显示了感叹号。如果您现在构建应用程序,您肯定会收到一些警告消息以及错误消息,并且构建失败并显示一些消息,如下所示。这是因为我们安装的 SQLite 不支持“Any CPU”处理器架构。

现在将目标平台从“任何 CPU”更改为您的 CPU 架构。就我而言,CPU 架构是 x64。下面指定了检查 CPU 架构的过程。

不确定这是否适用于 WPF 应用程序,但它适用于 Windows 商店应用程序。单击上面的链接以获取详细信息和屏幕截图。

希望这会帮助一些人;-)

于 2015-07-15T14:00:08.267 回答
1

在我的情况下,我只需将项目构建设置为x86x64 并将目标框架设置为 4。它不适用于更高的框架。

于 2016-10-10T07:42:01.263 回答