Windows Phone and SQL Lite: What’s the Current Situation?
Join the DZone community and get the full member experience.Join For Free
last week i spoke at an italian conference called windows phone developer day about sharing code between windows phone and windows 8. one of the topics was data access and how to share code to interact with a database between windows phone and windows 8.
people were a bit confused and i got many questions because i told them that sql lite is supported by windows phone 8 but can’t be used at the moment. what does it mean?
let’s make a step back: windows phone 7.5 has introduced support to relational databases thanks to sql ce (as database engine) and linq to sql (as manipulation library, to interact with the database using objects and classes instead of making queries). in windows phone 8 microsoft has decided to go another way, in order to use a solution easier to port to windows 8 and to other platforms: sql lite. in fact, this technology is cross platform and it’s available for android, ios, web application, client applications and much more. probably you’ll have to rewrite the data access layer (due to the differences between technologies and languages), but you’ll be able to reuse the database.
microsoft has worked with the team to provide an easy way to add sql lite to your windows 8 and windows phone 8 project: the result is that, in the visual studio gallery , you’ll find two extensions (one per platform) that can be used to add the sql lite engine to your project. the engine is written in native code : this means that you’ll need native code to interact with it and perform operations with the database.
and here comes the confusion i talked about in the beginning of the post: this extension allows you just to add the sql lite engine to your application, but doesn’t include a library to work with it using a high level language like c# or vb.net. the problem is that, for the moment, this library doesn’t exist for windows phone 8: the result is that, even if you can add it, you don’t have a way to perform operations with a sql lite database, unless you write by yourself a wrapper to the native libraries.
microsoft is committed into delivering a library as soon as possible, but at the moment we don’t have a release date yet.
on windows 8 the situation is a bit different, because such libraries already exist: one of the most popular is sqlite-net , on which i talked about in a previous post . unlucky, this library doesn’t work on windows phone 8, because it uses some features of the windows runtime that aren’t available in the windows phone subset.
in case you’re developing a windows phone application and you need to use a database, which are the possible solutions?
the first one is to keep using sql ce, that works just fine in windows phone 8: it’s a very good solution in case you don’t need to port your application to windows 8 or to another platform.
the second one is to use csharp-sqlite , that is a library published on google code that allows to use the sql lite engine in a c# application. the library is supported by windows phone 8, so you can use it to reuse your sql lite database in a windows phone application. the downside? the c# library is based on code that is part of the .net framework and that is not available in the windows runtime. this means that you’ll be able to reuse the database, but not the data access layer of your application.
and the third solution? simply just wait that a native library for windows phone 8 will be available
Published at DZone with permission of Matteo Pagani, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.