copy installed database to isolated storage

I’m working on an app that uses a simple, “pre-populated” database.  Of course the user can add or delete records as well.  For me, the easiest way to design and create the database, was to use the SQL Server 2008 R2 Management Studio.  So I used that to create a SQL Server CE database, with an .sdf file in a subfolder of my app project, and populate it using queries.    Let’s call that sdf file “myDB.sdf” and add it to the project.

So next I created a helper class called “DBMover.cs” which goes something like this (you may want to add exception handling):

So then in your App.xaml.cs file, in the Application_Launching event handler, call the helper method like this:

So there’s an easy approach to copying a database file to isolated storage on WP7.  You would still need to create the other necessary classes for your Model,  plus DataContext, etc in order to use the database, but that’s a topic for another day.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s