Take your Win8 Metro App to the Next Level with a SQLite DB

It's unfortunate Microsoft didn't include a database for use when building Windows 8 Metro Apps in C#. However, there is a very popular database known as SQLite, which works very well in mobile environments. SQLite is an extremely powerful and lightweight database used across many different platforms. SQLite allows you to create a minimalistic SQL style database contained within a single file. Unlike some mobile platforms, SQLite is not included out of the box for creating Windows 8 Metro apps. However, the SQLite team does provide a package, which allows you to include it within your project.

To get started, we first need to download and install the WinRT VSIX package from the SQLite download page. Once you have successfully downloaded and installed the package you will need to add a reference to it by right clicking on References and select Add Reference. You will then be presented with the Reference Manager as shown below.

Reference Manager
Reference Manager

Be sure to select SQLite for Windows Runtime and Microsoft Visual C++ Runtime Package. Since SQLite is a native package you will receive an error if you try to compile at this point. Instead you will need to change the project settings to change the Platform Target from Any Cpu to either x86, x64 or ARM. Next you will need a .Net driver for SQLite to use within your project. There are several different .Net drivers available. For this article we will use the sqlite-net, which can be installed via NuGet Package Manager and allows for use of LINQ as well as strongly typed operations. Right click on the project and select Manage NuGet Packages. Then search for the sqlite-net package as shown below.

NuGet Package manager
NuGet Package manager

Click Install for the sqlite-net package and follow the instructions. Once complete, close the NuGet Package Manager. You may notice that two additional C# files have been added to your application SQlite.cs and SQLiteAsync.cs. These two files include the source code for the sqlite-net driver, which will be compiled into your project.

Now that we have SQLite in our project as well as a driver, we can move forward with beginning to work with the database. In the snippet below we first create a string, which points to the correct path with the desired database name and extension. Next we create a new SQLiteConnection with the provided path and name within a using statement.

string dbpath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "mydb.db");

using (var db = new SQLite.SQLiteConnection(dbpath))

// Place code here


At this point we have a database connection; however, before we start creating tables, queries, etc., we need to define an object. For this article we will create a custom class called book, which will be used to define records within the book table. The book class definition is show below:

public class Book
public int ID { get; set; }
public string Title { get; set; }
public string Author { get; set; }

As you can see this is a very simple class; however you can provide additional definition within the class. For instance, on the ID field two attributes are included to identify the primary key and to enable auto-increment.

Now that we have the definition for the table, we can go ahead and created it as shown below:


This simple state is all we need to do to create a table within the database. Next we can go ahead and add a handful of records to the Book table.

db.RunInTransaction(() =>
for (int x = 0; x < 10; x++)
db.Insert(new Book() { Title = "Title-" + x.ToString(), Author = "Author " + x.ToString()

This block starts off by using a RunInTransaction statement with a lamda expression to include a for loop. Within the for loop, we call Insert on the db and pass in a new Book object each pass. The result is similar to inserting 10 records to a regular SQL database within a transaction. If an error occurs, the transaction will be rolled back. If we want to pull those records back we can use the Table method, which will return all records in the table as shown below.

var books = db.Table().ToList();

The books object will contain a complete list of records added to the book table.


As you can see it's not very difficult to use a SQLite database within your Windows 8 Metro app. The approach described above can be used for many apps that require a database; however, this approach does use a native DLL, which is why you need to change the Target Platform from Any CPU. If your application needs to maintain the ability to target Any CPU, you may need to go down a different path. One path, which may suit your application, is a project called C#SSQLite. The C#SQLite project is not a new driver for SQLite but instead a direct port over to C# and .Net. The C#SQLite project is maintained by a different team and work is currently underway to ensure it is compatible with the Windows 8 Metro platform. At the time of this writing the project was not ready for use in Metro apps; however, that may change in the near future.

Related Articles


  • Cash Settlement Buy Structured Settlements

    Posted by aledengatty on 06/20/2013 01:46pm

    loans for settlements superior fee is in the sort of fascination that a enterprise supplying this assistance is likely to charge. In evaluating a circumstance, I solicit opinions from expert demo lawyers in my business, their perception as to the value of my assert, and what a jury may possibly or may possibly not do. This forces them to either suspend those conditions entirely, or settle for unreasonably minimal pre-settlement funding features. Are you confronted with a comparable scenario. http://fundingsettlement.wordpress.com/2013/06/18/automobile-use-title-loans-to-obtain-your-girlfriend-some-bling-bling/ http://advancesettlementloans.wordpress.com/2013/06/18/federal-consolidation-loan-essential-challenges-to-think-about-qualifying/ http://settlementadvance.wordpress.com/2013/06/18/loans-with-lousy-credit-score-the-critical-to-securing-mortgage-approval/

  • VWTFS xGy LsWq

    Posted by ofaagFKdZg on 06/14/2013 07:28am

    generic propecia propecia side effects in women - buypropecia.org

  • 2013 experimental karen millen dresses quest of pay for

    Posted by goorsdoni on 06/04/2013 06:34pm

    From today, 12th November, until Sunday, you can bag yourself a fantastic?bargain?and support a good cause in association with Harpers Bazaar! The Gladrags and Handbags Designer Fashion Sale takes place [url=http://kmoutlet365.co.uk/]karen millen online[/url] at the Music Rooms, South Molton Lane in Mayfair and features menswear, womenswear and accessories that have been donated by [url=http://kmoutlet365.co.uk/]http://kmoutlet365.co.uk/[/url] top designer brands including Karen Millen.?All proceeds for the event go to help over 2,000 children in the UK have a magical Christmas via the Kids Company who provide?valuable?support to inner-city children. So,[url=http://kmoutlet365.co.uk/]http://kmoutlet365.co.uk/[/url] if you're on the hunt for this seasons 'must-have' bag or that sold out limited edition dress, you might just find it amongst one of the collections at the Music Rooms this weekend!Event details Gladrags & Handbags Designer Fashion Sale – 12-14 November 2010 The Music Room, South Molton Lane, London W1K 5AB Nearest tube: ?Bond StreetOpening times: Friday 12 November 9am-6pm Saturday 14 November 10am-5pm Sunday 15 November 11am-4pm

  • cheap baseball jerseys,cheap manchester united jerseys,cheap paintball jerseys

    Posted by Speapsusa on 06/03/2013 05:01am

    Berlusconi becoming more detailed for you to his or her wining, mainly because Allegri includes much near to the elegance, and the other can be difficult to acquire by means of this quick, Seedorf can be likely to be officially proclaimed sunday, although Galliani Possibly departing Allegri are not able to halt, although however wanting to pick out a different coach, in lieu of Seedorf. Italian media collective this Berlusconi just as before put off this getting together with, [url=http://socceryi.weebly.com]http://socceryi.weebly.com[/url] Allegri includes stated this elegance was above. "The market" can be considered Allegri soon after much more prospects options. Palermo that Gattuso received an call, although he quite simply would not take this. Seedorf can be Berlusconi's alternative, and is at the moment probably the most in all likelihood candidate. Apart from Marco van Basten and also Frank Rijkaard acquired recently been stated within the media, obviously, is currently within the young ones team coach Inzaghi. "Football market place, " said Seedorf ALTERNATING CURRENT Milan took this information might get proclaimed with From monday. ALTERNATING CURRENT Milan tale Costacurta includes explained to Heavens Sports Information, lurking behind this Dutch, he said: "Seedorf? Just about any regard by his or her appearance are great, I do think he was with ALTERNATING CURRENT Milan future year, as well can do very well, When i declare by means of these a lot of remark away, Clarence Seedorf and the co-operation of most are great. "But this means that this renowned press reporter Neisuo Di Seedorf is merely definitely not the proper person, [url=http://socceryi.weebly.com]wholesale football jerseys free shipping[/url] "Berlusconi in past times possess made a lot of great accomplishment, although When i really do not feel Seedorf could be the most suitable choice. " And also Nei Suodi just like the perspective Galliani previously disapprove guiding switch, he has already been the only Allegri formidable assistance of the judgement following a guiding switch throughout Berlusconi, Galliani as well contrary Seedorf took hence unskilled. Heavens Sports Main exchange pro Dumas financial Luxembourg last night discovered: "Allegri can sign up for this Italian capital final, if hence, in that case Galliani will endeavour for you to tell Berlusconi to simply accept Donadoni, in lieu of shellfish Berlusconi wanted Seedorf. "only regarding Parma, Ghirardi Donadoni have been too ashamed for you to dismissed. Renowned Press reporter Padovan of the "Italian sports", said: "In truth, this coach previously preferred, ALTERNATING CURRENT Milan could be the future brain coach Clarence Seedorf, Berlusconi have been preferred. "

  • Cheap NFL Jerseys China

    Posted by Dowphyponynug on 05/15/2013 08:45am

    Simply by placing your signature to Make, the particular Rams have got offered 2010 first-round select Mike Bradford having an further gun inside the transferring video game. The particular staff will be slender with extensive radio, in Make and also Puncture Kendricks, have got a couple of small, fitness and also adaptable limited comes to an end to be able to chuck with other safeguarding. Gleason enjoyed for your Team regarding half a dozen time of year now is suffering from ALS. This individual can not wander or perhaps discuss, and also his / her wheelchair will be match a particular device that enables any online words to be able to communicate regarding your pet. Welcome by way of a deafening spherical regarding applause from your masses with Radio stations Metropolis Audio Hallway, Gleason declared the particular Team have been using Terron Armstead. In the course of his / her half [url=http://www.wholesalejerseyschinastore.us/]Wholesale NFL Jerseys China[/url] a dozen [url=http://www.wholesalejerseyschinastore.us/]Wholesale NFL Jerseys Free Shipping[/url] periods with all the Team, Gleason has been any monster about specific clubs. This individual declared his / [url=http://www.wholesalejerseyschinastore.us/]Wholesale Jerseys Free Shipping[/url] her ALS prognosis inside 2011, and contains recently been campaigning to get a treatment ever since then. This has been any active Apr regarding your pet. Previous saturday and sunday, this individual has been on Machu Picchu together with past teammate Scott Fujita since this individual agreed upon his / her old age paperwork. (Getty Images)

  • Cheap Jerseys Free Shipping

    Posted by keddisplike on 05/14/2013 05:57pm

    Shutdown Nook will probably be [url=http://www.cheapjerseyschinastore.us/]Cheap Jerseys Free Shipping[/url] inside Lucas Acrylic Ground for your quarterback/receiver soccer drills for kids nowadays, and also we are going to up-date an individual on what these kinds of quickly fellas seemed any time working some approved avenues. ANY throat problem provides brought up any health-related reddish hole about Jarvis Jones (USA Nowadays Sporting activities Images)In a couple of periods with Ga, the particular 6-foot-3, 241-pound Jones acquired twenty eight totes then one interception and also has been 2 times known as a great All-American just before proclaiming early on for your set up following 2012 time of year. Jones will be widely-regarded being [url=http://www.cheapjerseyschinastore.us/]Cheap Jerseys Wholesale[/url] a prospective Top [url=http://www.cheapjerseyschinastore.us/]Cheap Jerseys USA[/url] select inside the 2013 AMERICAN FOOTBAL Set up and also consumes the particular Simply no. 10 i'm all over this the original " Shutdown Nook Huge Board". Armstead has an appealing account, even though. The particular 6-foot-5, 306-pound small-school superstar, which enjoyed sufficiently on the East-West Shrine Video game to be able to improve more attention, and also make a great invites for the Mature Pan as a possible injuries substitute.

  • authentic nfl jerseys,thailand netherlands jersey

    Posted by baltuntometle on 05/13/2013 03:20am

    Mourinho loves to obtain a substantial facility episode before, may hold the tennis ball, in addition to the employment of air conditioning superiority, disrupt the opposite bash collection. With this thought, Post Lukaku is actually likely to returning from Thib Bromwich, this individual experienced a fantastic months there (as of that saturday and sunday, Lukaku Sibrand obtained age 14 Highest regarded League targets, more than Chelsea's additional players in the League), more than a period of time, Lukaku is named a a fresh Drogba, [url=http://lovejerseys13.webs.com/]soccer jerseys china[/url] Mourinho regression, may make it possible for the tiny wow london stand out. Post also believe that, Mourinho shall be in search of any keep with regard to Chelsea midfielder Claude Makelele, sort. In the 12 months the fact that Chelsea crew, Makelele is often a particular products, nonetheless because Essien kept, you can state which Chelsea essential any jet fighter within this place. Moreover, Mourinho is additionally gonna give Lampard a fresh 2 year contract, when Chelsea hadn't executed in addition to Lampard's 2 year contract. Lampard in addition to Mourinho are actually good romance, Chelsea appeared to be in the maximum period, they want produced an awesome crew coordinate, with regard to so many a long time, that contribution regarding Lampard into the Chelsea is actually incomparable, when can see within Lampard before settlement, dealing with Mourinho once more, that may end up being a good matter. In case you notice Chelsea in the lineup, which includes the ones from that on-loan players for instance Lukaku, by way of example, you may see out, Chelsea side learning resource is actually so abundant. [url=http://lovejerseys13.webs.com/]wholesale soccer jerseys[/url] They want a good goalkeeper about lending product from Atletico This town (Courtois), I used to be advised which this individual belongs to the greatest goalkeepers within European countries, in addition to in the Chelsea goalkeeper place, Cech in addition to Turnbull have become good. Chelsea also by using Donald Lewis, the idea appears to be he or she is improving in addition to better. In the past, protecting blunders, this individual appeared to be accused regarding not a reduced amount of, nonetheless it appears to be this specific nonetheless make it possible for your ex mature. Donald Lewis also obtained several excellent universe say in addition to essential objective, since this individual lately produced alongside Fulham, in addition to at your home alongside Basel. That Doldrums own several quite successful approaching midfielder, Mata, Oscar in addition to Zal, nonetheless moreover, within '07 Mourinho kept that Standford fills, central is still that crew this individual kept, together about in addition to heli-copter flight industry, Lampard, Terry in addition to Ashley : Cole is still that team's important stats, in addition to Cole in addition to He uk, not one but two in the greatest kept backside regarding. In addition to Everton, for instance Bynes, Cole is additionally quite cut-throat, within his / her present state, at the least may perform for just two a long time in the top rated. Whenever Mourinho travelled in to the Standford fills checkpoint, he can notice several recognizable amiable face, which shall be his / her reconstruction of your fresh era regarding Chelsea.

  • Kawhi Leonard Jersey

    Posted by uncelmKen on 05/12/2013 06:21pm

    闁炽儲绐旈柍銉︾崱 not necessarily buying a terry around the glenohumeral joint coming from those who haven闁炽儲鐛?recently been right now there for me personally, 闁? Russell mentioned. 闁炽儲绐攖 [url=http://www.officialthundersteamstore.com/kevin-martin-jersey/]Kevin Martin Jersey[/url] can feel amusing not necessarily to endure an exercise get away, that闁炽儲鐛?exactly what [url=http://www.officialthundersteamstore.com/gary-payton-jersey/]Gary Payton Jersey[/url] I闁炽儲鐛?utilized to. It闁炽儲鐛?planning to sense ready to go again on the market once [url=http://www.officialthundersteamstore.com/kevin-martin-jersey/]Authentic Kevin Martin Jersey[/url] more. I am going to attempt. 闁? /p? Cincinnati given 2015 MLB All-Star gameWelcome for the AMERICAN FOOTBAL set up! We' lmost all become submitting each and every assortment while they are usually declared, detailed with back links to be able to fantastic pick-by-pick examination coming from our own homeowner set up specialist, Doug Farrar.

  • Wholesale NFL Jerseys

    Posted by Dowphyponynug on 05/11/2013 05:46pm

    Protection possess replied appropriately. Instructors tend to be constantly searching for ways of stress quarterbacks without having compromising or even diminishing protection. It閳ユ獨 the amounts online game, also it usually is going to be. How could you existing the actual false impression associated with stress without having really delivering much more rushers? The actual defense閳ユ獨 goal would be to pressure the actual criminal offense to improve the amount of move protectors past the actual 5 unpleasant linemen, to ensure [url=http://www.cheapjerseyschinastore.us/]Cheap Jerseys Supply[/url] that qualified receivers should turn out to be the main safety and for [url=http://www.cheapjerseyschinastore.us/]Cheap NFL Jerseys sUSA[/url] that reason can't discharge readily in to move paths. The actual protection desires much [url=http://www.cheapjerseyschinastore.us/]Cheap Jerseys Free Shipping[/url] more defenders to complement as much as less receivers. Which was the actual superseding idea from the area blitz (five move rushers) as well as area trade (four rushers along with a number of 2nd and/or 3rd degree defenders) ideas.

  • Cheap Jerseys Free Shipping

    Posted by RawSataDite on 05/11/2013 09:26am

    What went right: Perhaps the best aspect of the Cowboys' 2012 season was the development of Dez Bryant into a legitimate No. 1 [url=http://www.cheapjerseyschinastore.us/]Cheap Jerseys Supply[/url] receiver. Dogged by questions about his maturity continued into training camp as owner Jerry Jones created a set of rules for the 2010 first-round pick to follow in order to remain a Cowboy. Bryant may always push the envelope with his decision-making away from the field, but 2012 was his statement season between the white lines. Bryant caught 92 passes and led the Cowboys with 1,382 receiving yards and 12 receiving touchdowns, scoring 10 of his touchdowns during a [url=http://www.cheapjerseyschinastore.us/]Cheap NFL Jerseys Free Shipping[/url] seven-game stretch in the second half of the season. Tight end Jason Witten set an NFL single-season record for receptions by a tight [url=http://www.cheapjerseyschinastore.us/]Cheap Jerseys Wholesale[/url] end (110) and went over 1,000 receiving yards for the fourth time in his career. Witten was named to his eighth Pro Bowl and was a second-team All-Pro.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date