Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 21:48, 31 January 2014 by influencer (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Compiling and using SQLite with Windows Phone 8

From Wiki
Jump to: navigation, search

This article explains how to compile and use public SQLite with Windows Phone 8.

WP Metro Icon File.png
WP Metro Icon Tools.png
WP Metro Icon WP8.png
Article Metadata
Tested with
SDK: Windows Phone 8.0 SDK
Windows Phone 8
Created: vinayppatil (17 Jan 2014)
Last edited: influencer (31 Jan 2014)



This wiki explains how to use SQLite in Windows Phone 8 applications. It explains how to modify the open source SQLite source code and compile it for use in your Windows Phone 8 applications.

This wiki takes you through the following steps:

  1. Compiling the SQLite source code for ARM and x86 targets
  2. Creating an Extension SDK targeted to Windows Phone 8
  3. Using SQLite with your Windows Phone 8 applications


Before you begin, you will need:

Compiling SQLite

Following the instructions in the sections below compile SQLite for ARM and x86 architectures.

Building binaries for an ARM target

  1. Open Visual Studio 2012 ARM Phone Tools Command Prompt in administrator mode.
  2. Navigate to where you want to put the source or create a directory:
    mkdir c:\sqlite-arm
    cd c:\sqlite-arm
  3. Get the latest SQLite source code:
    fossil clone sqlite3.fossil
  4. Open the repository you just created:
    fossil open sqlite3.fossil
  5. Type in the commands below in order:
    SET NCRTLIBPATH=%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\VC\WPSDK\WP80\lib
    SET NSDKLIBPATH=%ProgramFiles(x86)%\Windows Phone Kits\8.0\lib\x86
    SET USE_RC=0
    nmake /F Makefile.msc sqlite3.c XCOMPILE=1 USE_NATIVE_LIBPATHS=1 FOR_WINRT=1 NO_TCL=1
    nmake -f Makefile.msc sqlite3.dll /I XCOMPILE=1 USE_NATIVE_LIBPATHS=1 FOR_WINRT=1 NO_TCL=1
Final binaries

When you're done, the c:\sqlite-arm source directory should contain sqlite3.dll, sqlite3.h, sqlite3.lib and sqlite3.pdb along with a lot of other generated files.

Building binaries for a x86 target

  1. Open the Visual Studio 2012 x86 Phone Tools Command Prompt in administrator mode.
  2. Create a source directory and navigate to it.
    mkdir c:\sqlite-x86
    cd c:\sqlite-x86
  3. Follow steps 3, 4 and 5 building binaries for ARM target.

Final binaries

When you're done, the c:\sqlite-x86 source directory should contain sqlite3.dll, sqlite3.h, sqlite3.lib and sqlite3.pdb along with a lot of other generated files.

Building the Extension SDK

Now that we have all the required binaries, we will create an Extension SDK targeted to Windows Phone 8.

  • Create a new project by selecting File -> New -> Project -> Visual C# -> Extensibility -> VSIX project
  • Create a new file your_proj_name.props and copy the source code below into it. (Make sure to replace your_proj_name and version accordingly.)
    <?xml version="1.0" encoding="utf-8"?>
    <Project xmlns="">
    <PackageConfiguration Condition="'$(Configuration)' == ''">Debug</PackageConfiguration>
    <PackageConfiguration Condition="'$(Configuration)' == 'Debug'">Debug</PackageConfiguration>
    <PackageConfiguration Condition="'$(Configuration)' == 'Release'">Retail</PackageConfiguration>
    <IncludePath>$(FrameworkSDKRoot)\..\..\Windows Phone\v8.0\ExtensionSDKs\your_proj_name\version\DesignTime\CommonConfiguration\Neutral;$(IncludePath)</IncludePath>
    <LibraryPath>$(FrameworkSDKRoot)\..\..\Windows Phone\v8.0\ExtensionSDKs\your_proj_name\version\DesignTime\$(PackageConfiguration)\$(PlatformTarget);$(LibraryPath)</LibraryPath>
    <PropertySheetDisplayName> your_proj_name, version</PropertySheetDisplayName>
  • Create a new file called SDKManifest.xml in the project root, and copy the XML below into it. (Make sure to replace your_proj_name accordingly.)
    <?xml version="1.0" encoding="utf-8" ?>
    DisplayName="MySQLite for Windows Phone"
  • Create the hierarchy below in the application source, and add the files that were generated during build process to the project. Files from sqlite-x86 go into x86 folders. Files from sqlite-arm go into ARM folders.
    Extension SDK hierarchy
  • Right click on file, click on Properties and change Build Action to Content, Copy to output directory to Copy always and Include in VSIX to True. Repeat this for all the added files.
  • Double click on source.extension.vsixmanifest.
  • Input the options below on the install targets tab.
    install targets tab options
  • Input the options below in the asset tab.
    assets tab options
  • Now build the project. A .VSIX file should be generated in the bin/{config} folder.

SQLite Usage

  • Install the MySQLite Extension SDK you just created on your computer and restart Visual Studio.
  • Create a new Windows phone application.
  • Download sqlite-net-wp8 and add the Sqlite.vcxproj project to your solution by selecting File -> Add -> Existing Project.
  • Add the required compilation symbols as follows:
    Right click on Windows Phone Project -> Properties
    Click on the Build tab.
    In the Configuration dropdown, select All configurations.
    In the Platform dropdown, select All platforms.
    Add USE_WP8_NATIVE_SQLITE;WINDOWS_PHONE;SILVERLIGHT to the Conditional compilation symbols textbox.
  • Add a reference to the SQLite extension to the sqlite project as follows:
    Right click on SQLite Project -> Properties.
    Click on the Common properties tab.
    Remove SQLite.WP80 from the references.
    Click on Add new reference
    Select Windows Phone -> Extensions -> SQLite extension
  • Add the sqlite-net nuget package to the Windows Phone project.
  • Once this is done, you can use the database as you wish.
This page was last modified on 31 January 2014, at 21:48.
171 page views in the last 30 days.