Today we are going to look at how we can use SQLite for Windows Phone 8.

There are many posts out there that serves the purpose, but only half of it, today we will resolve the issues and would make sure the project runs fine.

Building the Solutions

to build the solution and run the attached sample you will need visual studio 2012 or higher running on windows 8 Professional x64. The Computer will also need to have a microprocessor that Suppots SLAT (Secondary Level Address Translation) 

Step1

Create a windows Phone Project in Visual Studio

In order to integrate SQLite in Windows Phone, you need to have SQLite for Windows Phone. and that can be installed from Tools > Extensions and Updates.

Once installed, right click on References with in your project, and select Add reference

On the Immediate windows, select windows Phone 8.1 > Extensions > SQLite for Windows Phone.

The Reference has been added to the project. Build the Project and you will get an Error and exclamation sign next to SQlite for windows Phone

 

The Error says to change the target processor Architecture through the Configuration Manager. 

To do that, right click Solution and select Configuration Manager, and change the Active Solution Platform from Any CPU to ARM, as shown in the picture below

Rebuild the Solution again and the Problem should go away.

Next, we need to Add Sqlite-net from Nuget.

Right Click References and Select Manage Nuget Packages. In the Immediate windows Search for Sqlite-net, Make sure your Internet is working fine.

This will Add two C# files to the Solution

Next, we are going to Add a Project to our Solution that i have Added as an attachment, you can also get this from Github by searching Sqlite-net-wp8

Right click on the Solution, select Add > Existing Project, Add the Sqlite-net-wp8 C++ project that i have added as an attachment. Your Project will look like this.

Now, From windows Phone project, Right Click References and select Add Reference

in the Immediate window, Select Solution and Select SQlite

This will add, a Reference to your windows Phone project for the SQlite C++ project.

 Build the Project and you will receive three errors as shown.

Double click on the error and it will take you to SqLite.cs, 

it is because you need to add USE_WP8_NATIVE_SQLITE to your Conditional Symbol, to do that right click your Windows Phone Project and Select Properties

in the Properties Windows, Select Build from the Left Section, and in the Conditional Compilation Symbols, put a semicolon and paste USE_WP8_NATIVE_SQLITE.

Save All and Build the Project, if you have done everything rite, your project will compile just fine.

Download the Attachment that contains the working project and Sqlite-net-wp8 from Github.