Tuesday, October 30, 2007

SQL Server Compact Edition Multi-User Access

While trolling the SQL Server Compact Edition forum today I saw another post from someone wanting to know if SSCE is truly a single-user database given that it allows up to 256 connections. The poster then goes on to ask:

"Could CE be extended for use as a multi-user DB Server by creating a custom server such as a .NET Remoting Server hosted through a Windows Service (or any other custom host) on a machine whereby the CE DB would run in-process with this server on the machine which would then be accessed by multiple users from multiple machines"

I was going to provide the stock standard answer of no but got thinking and decided to ask Nick Randolph. It turns out that this response is not entirely correct as Nick pointed me to a blog entry he did some time ago about using SQL Server CE as ASP.NET Database. So, all those people saying no (including myself) are wrong. It can be done.

Now that's cleared up, would you really want to do this? Don't get me wrong. I love SSCE and it's a great product; but why would you want to host it on a server? Why the fascination with multi-user access? Yes SSCE is free, but so is SQL Server Express and it allows multi-user access. A SQL Server Express database is also upgradeable to SQL Server whereas a SSCE database isn't. Not to mention that SSCE only supports a:

  • Subset of T-SQL
  • Subset of in-built SQL Server functions
  • Subset of SQL Server datatypes
    • Not Supported: decimal, smallmoney, smalldatetime, char, varchar, text,
      timestamp, sql_variant, xml

and SSCE does not support:

  • Stored Procedures‘
  • User-defined Functions (UDF’s)
  • Any CLR UDT Datatypes
  • XML schema collections
  • Queries with multiple statements

So is there a real need to create multi-user applications that access a SSCE database or is it just a fad? Would be interested to hear your thoughts.

Cheers
Jeff

3 comments:

Christopher Fairbairn said...

I'm not so sure about using it as the backend of a ASP.NET application, but I have used SQL Server Compact Edition within the ASP.NET environment before.

In one project we utilised it within ASP.NET to build slightly customised SDF files for eventual download and use on a PDA.

The website was basically used to data mine a SQL Server 2005 database, with the option to download a SDF file for use on a PDA etc once the nesscary data was obtained.

This involved using the 'trick' mentioned by Nick Randolph in order to get SSCE working within the ASP.NET environment. As Nick's article said:

"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."

Jeff Wharton said...

Hi Christopher,

This is something that I'm going to start playing around with as the whole idea of creating SDF's on the server for easy download to PDA's is great. Also like how you're using it to provide users with a snapshot of a masters database. perfect for analysis and read-only data and so much easier to setup than merge replication.

Thanks for your comments.

Cheers
Jeff

ErikEJ said...

Hi Jeff,
I have actually done a project which involved a web service for providing zipped initial sync sdf files to merge subscribers, basically building the sdf file on the server on-demand from the Pocket PC app. We got some interesting (ie good) performance benefits from this approach