software solutions for a mobile world

Syncing Windows Phone database with backend SQL Server

Andy Wigley

Windows Phone 7 was first released without any local database support which caused raised eyebrows from me and other MVPs who had a background in building Line of Business apps. Over a year ago, I posted about a port of the Perst C# database which had been developed by McObject for a number of  clients including desktop Silverlight. I’m pleased to say that McObject were inspired enough by my efforts to add proper support for Windows Phone 7 into their official download which you can get here.

At APPA Mundi, we built and deployed what I’m pretty sure was the first ‘proper’ line of business app for a commercial client in the U.S. in which we populated Perst databases on the server and then copied the database file down to the client. The database has many tens of thousands of records in it, and the app worked – and still works – well. I won’t tell you the name, as you will not be able to find it in marketplace as it is a private distribution.

Since then, Microsoft has released Windows Phone 7.1 SDK, better known as ‘Mango’, which includes support for LINQ to SQL which you can use to access SQL Server Compact databases on the client. Nonetheless, Perst remains a valuable alternative to L2S and can outperform it in many situations.

So, now that we have a choice of databases we can use on the client side, the new ‘ask’ that has gone straight to the top of the ‘Requested New Features’ lists is the ability to sync a local database with a backend database. There’s no solution been announced for LINQ to SQL, but last week McObject announced that the MediFox company have developed a Perst Sync provider which implements the client-side plumbing for a sync solution built around the Microsoft Sync Framework Toolkit. The PerstSyncProvider synchronization code may be downloaded for free at perstsyncprovider.codeplex.com.

The download includes the code for the sync provider and also a simple demo app that shows how you can sync with the sample ListService that you can build from the Microsoft Sync Framework Toolkit. It doesn’t show much in the way of UI, but the code underneath illustrates how easy it is to work with:

image

Read more about the Perst Sync provider here at Windows for Devices.

The Microsoft Sync Framework Toolkit allows you to create your own sync solutions by provisioning a database with the required sync tracking tables and columns and then exposing a WCF sync service to clients. The server side works with SQL Server out of the box, but it should be simple enough to extend to other databases. On the wire, sync is handled by extensions to the OData protocols. Don’t be fooled into thinking it’s a simple click and deploy solution though: this is a *framework* so be prepared to invest some time into this reading the documentation and studying the samples if you want to build your own sync solution. The toolkit comes with sample clients for HTML5, desktop Silverlight, Windows Phone 7 (synchronizing to flat files in Isolated Storage) and Windows Mobile 6.5.


Posted Dec 07 2011, 12:47 PM by Andy Wigley
Copyright © 2014 APPA Mundi Limited. All Rights Reserved. Terms of Use and Privacy Policy. OrcsWeb's Windows Cloud Server Hosting