Home > Uncategorized > Embed Prepopulated SQL server db in Windows Phone app

Embed Prepopulated SQL server db in Windows Phone app

This is a easy way to embed a Prepopulated  SQL server database (read-only) into a Windows Phone app.

Include SDF into project at root level, mark it as “build-action: embed”

Using the SQL CE toolbox, generate a context class (http://sqlcetoolbox.codeplex.com/releases/view/104781), include this in your project.

Make a reference to system.data.linq

– I found I needed to comment out the lines containing “IDbConnection” but that might not be applicable.

Then the code for a select is simple:

using (dictContext db = new dictContext(“Data Source=appdata:/dict.sdf;File Mode=Read Only; Max Database Size = 512;”))
{
var translations = db.Dictionary.Where(d => d.Word == “CAT”);
MessageBox.Show(translations.First().Fr);
}

 

 

 

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: