Extracting a SQL CE DB from Isolated Storage in WP7 Mango.

3 minute read

Introduction

By now most of you have heard that Windows Phone 7 – Mango release will support Local Databases (SQL CE) using Linq to SQL. But what you probably haven’t heard much about is how to extract the .SDF that is created in isolated storage to your local computer and view the contents. I find this extremely important for debugging application and making sure my database is setup exactly like I want it. So that is what we are going to do today.

Getting Started with a sample application:

Local Database Sample

For this tutorial we will need a sample application that uses a local database. If you are already using a local database (SQL CE) in your mango application then you can skip this section otherwise go ahead and download the “Local Database Sample” from MSDN.

Below is an excerpt from the MSDN Page

On Windows Phone OS 7.1 you can use LINQ to SQL to store relational data in a local database that resides in your application’s isolated storage container. This sample is a to-do list application that uses a multi-table local database. Items that appear in the list are added updated and deleted from a local database where they will persist between application launches. For step-by-step information about how to develop this application see How to: Create a Local Database Application with MVVM for Windows Phone.

Download Sample: C# | VB

The Database Structure

We see code that defines our database name in App.xaml.cs. It is simply called ToDo.sdf:

// Specify the local database connection string.  string DBConnectionString = "Data Source=isostore:/ToDo.sdf";

And code that creates a table and defines the columns

[Table]  public class ToDoItem  {      [Column( IsPrimaryKey = true )]      public int ToDoItemId { get; set; }         [Column]      public string ItemName { get; set; }         [Column]      public bool IsComplete { get; set; }         [Column]      public int _categoryId { get; set; }         [Column]      private Binary _version { get; set; }  }

Please note that I removed all code relating to MVVM to simplify this example. If you wish to see the code then please review Model –> ToDoDataContext.cs. This sample also has another Table called ToDoCategory that was not included in this tutorial. 

Now that we have reviewed what the database looks like lets see what it takes to extract the .SDF file from isolated storage to our local pc.

Get the required tools if you haven’t already.

  1. Download the Windows Phone SDK 7.1 RC and install it if you already have not.
  2. Grab the Silverlight Toolkit for Mango.
  3. Download the “Local Database Sample” from MSDN if you want to use this example.

Go ahead and run the application and enter some data. My screen looks like this:

image

This should be enough data for us to work with.

 

Leave the emulator running and navigate to the Properties –> WMAppManifest.xml file. Open up notepad and copy/paste the ProductId into it.

image 

Go ahead and navigate over to your “C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Tools\IsolatedStorageExplorerTool” and run the following command:

ISETool.exe ts xd 888a966b-516e-4f9d-a6c3-343454e07466 "C:\Users\MichaelCrump\Desktop\IsoStore"

You should:

  • Replace the GUID with your own.
  • Give it a proper file location to output the file.

Here is what my command window looks like:

SNAGHTMLcd2a9

Note: I kept getting this message that is was already being used but it actually built the file anyways.

Navigate over to the directory that you specified earlier and you will see your .SDF file from IsolatedStorage. Pretty cool huh?

SNAGHTMLf7cfc

 

Go ahead and switch over to Server Explorer inside of Visual Studio 2010 and let’s add that SDF to the project. Right click on Data Connection then select “Add Connection”.

 

image

 

Make sure you select the Data Source to be: SQL Server Compact 3.5 and then hit Browser and select the .SDF file just created.

Please note that I could not get SQL Server Compact 4.0 Data Source to work with this sample.

SNAGHTML129bd1

Hit OK and you should see your database that you crated in Mango (that was living in Isolated Storage) inside of Visu

Updated:

Leave a Comment