简体   繁体   中英

Using SQLite-net in a WPF app

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 implementation there, but now I can't seem to do that with my WPF app.

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.

在此输入图像描述

What am I doing wrong? All the tutorials I find tell me to use System.Data.Sqlite instead but I don't want to rewrite all my DAL code again

I got it working.

For anyone who's trying to do this - specifically, trying to get sqlite-NET to work on WPF, not just SQLite, you need to:

  1. download the pre-compiled windows binary of sqlite3.dll from http://www.sqlite.org/download.html
  2. copy that dll file into your bin folder
  3. go to project properties > build and change the CPU type to x86 (there's no precompiled x64 version at time of writing)

You need to download and install an appropriate System.Data.SQLite setup package from http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki .

This will install the required SQLIte assemblies into your GAC and the design-time components for 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

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

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

Once you do that you will be able to add required SQLite assembly references in your project.

Here is a screenshot of SQLite assemblies in Add Reference dialog:

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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