SQL Server CE as ASP.NET Database

Champion of occasionally connected (aka smart client) data, Steve Lasker, has posted on how to configure SQL Server CE to run as a database for your ASP.NET website.  Essentially it is a simple as adding the following line of code:

AppDomain.CurrentDomain.SetData(“SQLServerEverywhereUnderWebHosting”, true)

As Steve points out the scenario that this was originally added for was building sdf files (ie SQL Server CE database files) on the server side before being shipped out to the device.  Although merge replication is great for synchronising changes.  Unfortunately it is not particularly good for the initial download of data to the device.  I recently synchronised (from scratch) a 20Mb datafile to my K-Jam and it took over an hour (requiring continuous connectivity during this time).  The actual download of data took only a fraction of that time; it appears that a significant amount of time is taken applying the data to the database.  As such it is preferable, for the initial setup, to build this file on the server and just download it to the device.

In my previous post I have started to put together some tools for working and debugging merge replication.  Unfortunately I’m still having issues with the ClickOnce deployment of the SyncTester app.  The second app to be put together is going to be a webservice that can be used to prebuild a SQL Server CE database with specific publications.  The scenario goes a bit like this:  Your application starts up, determines that it doesn’t have a database, makes a call to the webservice (passing through the details of the publications that it wants the database to be subscribed to), the webservice communicates to the server database and builds the sdf file, the webservice passes back the download location for the sdf file (or you could actually pass back the sdf from the webservice), the sdf file is downloaded and the application continues to load.  More info on this app when I get time to build it 😉

Leave a comment