Getting Started with SQL Server Compact Edition

What is SQL Server Compact Edition?

As I blogged about last week (http://arcanecode.wordpress.com/2007/01/15/sql-server-compact-edition-released/), Microsoft has released SQL Server Compact Edition. SSCE is not new, although it carries a new name and new, expanded functionality. It’s roots extend back to the SQL Server for CE and SQL Server Mobile framework.

Microsoft recognized the need for a robust, secure database that can bridge the gap between the mobile world and the server world, and at the same time meet a need for the desktop environment. SSCE is, at its heart, a database, and nothing else.

Unlike its bigger relatives, from SQL Server Express on up, it does not run as a service. Instead, it’s a set of DLLs that you call from within your programming environment. It’s designed to have a very small footprint, the DLLs take less than 2 megabytes of space.

With SSCE you can create a database that resides in a single file, with a default extension of sdf. You can create tables, indexes and that’s about it. No stored procedures, only one user can be in the database at a time.

I know it doesn’t sound like much, but it fits an important need. First off, the database can be password protected and encrypted, to make it secure. Second, it is transportable. The database can run on both mobile devices like smart phones or PDAs, and on the desktop. You can easily move the file around, back it up, even e-mail it. After all it’s a single file, and since SSCE doesn’t run as a service it’s not locked when your app isn’t running.

SSCE also supports replication, you can replicate between it and a full blown SQL Server install. SQL Server Integration Services also works with it, making it easy to move data between your SSCE database and larger systems.

Haven’t I seen this before?

For a little while SQL Server Compact Edition was known as SQL Server Everywhere. Frankly I liked the Everywhere name better, but that’s just my opinion. I mention this because there have been some articles and books (Programming SQL Server 2005 by Andrew Brust and Stephen Forte, for example) that talk about the Everywhere edition.

The important thing to note is SQL Server Everywhere and SQL Server Compact Edition are the same thing.

Places to use SQL Server Compact Edition

So when do you use SSCE? Well, if you want to develop a database app that will run on a mobile device, this is your only choice. (Well, outside of developing a web app, but we’re talking an app that will run totally independently of external influences).

If you are developing a Windows based application, for a single user, and you need a local database just to hold some data, SSCE is a good choice. For example, a salesman could have an application with his companies product table and sales tables loaded. He could take his laptop to the field, place orders, then have the app resync when he returns to the office.

In my own case, I have an app that generates graphs from a specific dataset. This data is gathered from multiple databases. To create one chart takes about 1 to 2 minutes depending on how many users, amount of data, etc. That doesn’t sound like much, but they look at 12 to 18 reports every morning, that’s a lot of time for a Vice President, Plant Manager, and six other top guys to sit around waiting. Instead I’ll be using SSCE to cache the data locally. It takes about 3 minutes to pull down the data, but after that each chart generates in about one third of a second. Quite an improvement!

If you need multiple users, to store your data on the network, or have stored procedures, you will need to move up the food chain to something like SQL Server Express. If you need more info, there is an excellent article at http://www.microsoft.com/sql/editions/compact/sscecomparison.mspx that contrasts the differences between SSCE and SQL Server Express.

What do I need?

OK, you’ve decided to take the plunge and look into SSCE. Well first, you need to get SSCE and install on your development system. I provided a link in last week’s post, but in case you missed it you can download SSCE from http://shrinkster.com/l9f.

Next, you need to install Visual Studio Service Pack 1. VS SP1 will correct add some intellisense and correct some naming issues (for example the reference shows as SQL Server Mobile prior to installing SP1). In addition it’s probably a good idea to install SP1 anyway, to correct various issues. You can get your copy from http://msdn.microsoft.com/vstudio/support/vs2005sp1/default.aspx or http://shrinkster.com/lel.

Next, you will want the SQL Server Compact Edition Books On Line (that’s a mouthful, we’ll call it SSCE BOL from now on). You can get these at http://www.microsoft.com/downloads/details.aspx?FamilyId=E6BC81E8-175B-46EA-86A0-C9DACAA84C85&displaylang=en or http://shrinkster.com/lem. These have essential documentation for understanding SSCE.

Update (April 24, 2007): It turns out there is a fourth component you will want, the SQL Server Compact Edition Tools for Visual Studio 2005, Service Pack 1. See my post on April 24th (http://shrinkster.com/ob4) for details and where to download it from. If you want you can go ahead and finish this post first, as you will install this component as the final step.

How do I learn this stuff?

First off, the SSCE BOL is a good resource, it has lots of links and information on how to use SSCE. I admit though it’s laid out like a help file, for learning it isn’t laid out in a logical chapter by chapter manner.

Microsoft has some “How To” tutorials at http://msdn2.microsoft.com/en-us/sql/bb219480.aspx or http://shrinkster.com/len . They come in both C# and VB.Net flavors, and step you through various topics.

There are two spots on Microsoft that are launching points for SSCE. The main site off the SQL Server area is http://www.microsoft.com/sql/editions/compact/default.mspx (or http://shrinkster.com/leo). The MSDN site is http://msdn2.microsoft.com/en-us/sql/bb204609.aspx (or http://shrinkster.com/lep).

SQL Server Guru Bill Vaughn has written an excellent E-Book on SSCE. Of all the resources I’ve mentioned this is probably the best, although you do have to purchase it (dirt cheap). Bill’s site for his Hitchhiker’s Guides is http://www.hitchhikerguides.net/, the E-Book I’m speaking of is at http://www.hitchhikerguides.net/EBooks/5582.aspx. At 20 bucks it’s well worth the investment. (Standard disclaimer, I don’t make any money off sales of the book, Bill’s site, or anything else associated with the Hitchhiker’s guides. )

Finally, I’ll spend a few days talking about what I’ve learned from all these sources, showing you what I’ve done with this new technology. Hopefully I’ll help you shortcut some of the learning pains I’ve gone through.

 

About these ads

5 Responses to “Getting Started with SQL Server Compact Edition”

  1. gustavg Says:

    neat! the info you need to know in one place. thanks!

  2. Ayman Says:

    Many thanks for your all SQL server/CE related topics.

  3. Datenbank unter Visual Basic .net - .NET Caf @ tutorials.de: Forum, Tutorial, Anleitung, Schulung & Hilfe Says:

    [...] Datenbank unter Visual Basic .net Hallo, Getting Started with SQL Server Compact Edition SQL Server Compact Edition with C# and VB.NET (Etwas hinunter scrollen, dann gibt es auch VB.NET [...]

  4. Nutan Talwar Says:

    Thank you for the detailed info. about the Compact.
    I was confused over Compact and Express Editions, your web page came to rescue. Thanks again, Cheers!

  5. Tony Says:

    thanks for ypur help
    after i download and setup all required,
    database type is disabled
    i cant chose SQL Server Compact Edition
    so what i can do


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

Follow

Get every new post delivered to your Inbox.

Join 94 other followers

%d bloggers like this: