在 WPF 应用程序中使用 SQLite-net
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23432730/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using SQLite-net in a WPF app
提问by roryok
I'm having a bit of a senior moment trying to get SQLite working on a new WPF project. I've recently written a bunch of Windows Store and Phone projects and always used the same neat SQLite-net implementationthere, but now I can't seem to do that with my WPF app.
我在尝试让 SQLite 在一个新的 WPF 项目上工作时有一些高级时刻。我最近写了一堆 Windows Store 和 Phone 项目,并且总是在那里使用相同的简洁 SQLite-net 实现,但现在我似乎无法用我的 WPF 应用程序做到这一点。
I've added SQLite-net through nuget, but I can't find a version of SQLite3.dll that I can add to the project. When I download it from SQLite.org I get the following error.
我已经通过 nuget 添加了 SQLite-net,但是我找不到可以添加到项目中的 SQLite3.dll 版本。当我从 SQLite.org 下载它时,出现以下错误。


What am I doing wrong? All the tutorials I find tell me to use System.Data.Sqliteinstead but I don't want to rewrite all my DAL code again
我究竟做错了什么?我找到的所有教程都告诉我System.Data.Sqlite改用,但我不想再次重写我所有的 DAL 代码
回答by roryok
I got it working.
我让它工作了。
For anyone who's trying to do this - specifically, trying to get sqlite-NETto work on WPF, not just SQLite, you need to:
对于任何试图这样做的人 - 特别是,试图让sqlite-NET在 WPF 上工作,而不仅仅是 SQLite,你需要:
- download the pre-compiled windows binary of sqlite3.dll from http://www.sqlite.org/download.html
- copy that dll file into your bin folder
- go to project properties > build and change the CPU type to x86 (there's no precompiled x64 version at time of writing)
- 从http://www.sqlite.org/download.html下载 sqlite3.dll 的预编译 windows 二进制文件
- 将该dll文件复制到您的bin文件夹中
- 转到项目属性 > 构建并将 CPU 类型更改为 x86(在撰写本文时没有预编译的 x64 版本)
回答by Dean Kuga
You need to download and install an appropriate System.Data.SQLitesetup package from http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki.
您需要从http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki下载并安装适当的System.Data.SQLite安装包。
This will install the required SQLIte assemblies into your GAC and the design-time components for Visual Studio.
这会将所需的 SQLIte 程序集安装到您的 GAC 和 Visual Studio 的设计时组件中。
For .NET 4.5.1 (VS 2013) the current link is http://system.data.sqlite.org/downloads/1.0.92.0/sqlite-netFx451-setup-bundle-x86-2013-1.0.92.0.exe
对于 .NET 4.5.1 (VS 2013),当前链接是http://system.data.sqlite.org/downloads/1.0.92.0/sqlite-netFx451-setup-bundle-x86-2013-1.0.92.0.exe
For .NET 4.5 (VS 2012) the current link is http://system.data.sqlite.org/downloads/1.0.92.0/sqlite-netFx45-setup-bundle-x86-2012-1.0.92.0.exe
对于 .NET 4.5 (VS 2012),当前链接是http://system.data.sqlite.org/downloads/1.0.92.0/sqlite-netFx45-setup-bundle-x86-2012-1.0.92.0.exe
For .NET 4 (VS 2010) the current link is http://system.data.sqlite.org/downloads/1.0.92.0/sqlite-netFx40-setup-bundle-x86-2010-1.0.92.0.exe
对于 .NET 4 (VS 2010),当前链接是http://system.data.sqlite.org/downloads/1.0.92.0/sqlite-netFx40-setup-bundle-x86-2010-1.0.92.0.exe
Once you do that you will be able to add required SQLite assembly references in your project.
完成此操作后,您将能够在项目中添加所需的 SQLite 程序集引用。
Here is a screenshot of SQLite assemblies in Add Reference dialog:
这是添加引用对话框中 SQLite 程序集的屏幕截图:



