Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using SQLite-net in a WPF app

Tags:

c#

sqlite

wpf

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.

enter image description here

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

like image 798
roryok Avatar asked May 02 '14 16:05

roryok


People also ask

Can I use SQLite with C#?

SQLite is open source file system database. Unlike SQL Server, this doesn't require any Service to interact with the database but the real problem occurs, when we try to interact with SQLite DB in C#. There is no proper Entity Framework support available, as of now. Thus, we are compelled to use inline queries.

How do I connect SQLite to a Windows application?

Open your Visual Studio and select new project and in Visual C# select "Windows Forms Application" and provide the name as Sqlite and click on OK. Right-click on your application and select "Open folder in your window application" and then go to: BIN -> Debug and extract your application here.

How do I add SQLite to Visual Studio?

Open Visual Studio, select new project, and, in Visual C#, select “Console Application” and provide the name as SQLiteDemo. Click OK. To connect SQLite with C#, we need drivers. Install all required SQLite resources from the NuGet package, as pictured in Figure 1.


1 Answers

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)
like image 192
roryok Avatar answered Oct 04 '22 14:10

roryok