Wednesday, May 18, 2011

Using the Microsoft Desktop Stack – Part 1: Setting up SQL Compact 4.0 for Private Deployment

Introduction
Microsoft has revamped its desktop application stack in the past few years, moving from WinForms to WPF, from ADO.NET to the Entity Framework, and from the Jet database engine to SQL Server Compact Edition. This series of articles explains how to use the stack and presents checklists for implementing it.

The series consists of three articles:

Part 1: Setting up SQL Compact 4.0 for Private Deployment
Part 2: Using Entity Framework 4.0 with SQL Compact 4.0
Part 3: Using Entity Framework 4 in an MVVM Application

Parts 1 and 2 contain checklists for setting up SQL Compact and Entity Framework for a desktop application. Part 3 shows how to integrate Entity Framework 4 into a WPF application using the MVVM pattern. The demo app is included with Part 3. The series assumes the developer is working with Visual Studio 2010 (VS 2010), Entity Framework 4.0 (EF 4), and SQL Server Compact Edition 4.0 (SQL Compact 4).

The first step in working with the MS Desktop Stack is typically to create a project and configure it to support SQL Compact 4.0. This first article in the series describes how to set up SQL Compact 4.0 for ‘private deployment’ with a Windows desktop application. You can find additional information on this subject in the SQL Server Compact Development Guide:

Building Applications for Desktops (SQL Server Compact)
Private Deployment vs. Central Deployment (SQL Server Compact)
Private deployment refers to installing the SQL Compact 4.0 runtime in your application’s output folder, rather than relying on a global installation on the end user’s machine. It eliminates the need for a separate installation of SQL Compact on the end user’s machine, and it avoids the versioning problems that can arise if a global installation of SQL Compact is upgraded to a later version. The private deployment referred to in this article includes the support files required to use Entity Framework 4.0 with SQL Compact 4.0.

This article also explains how to include SQL Compact database files in a SQL Compact installation. The procedure differs depending on the role of the database file to be included, and it can present unusual and challenging issues.
The checklist in this article assumes that you are developing on a 64-bit machine. In that case, the global SQL Compact 4.0 installation folder on your development machine will contain 32 and 64-bit versions of SQL Compact 4.0. The checklist shows how to install both versions on a target machine; the correct one will be selected automatically at run time.


Step 1: Configure the Project
The first step in setting up a SQL Compact 4.0 private deployment is to create the required folder structure in the target solution.

Step 1a – Create a project library folder: First, if you haven’t already done so, create a project library folder in the root folder of your VS 2010 solution. In the examples below, the library folder is named Library.

Step 1b – Create a SQL Compact subfolder: Next, create a subfolder under the Library folder to hold the SQL Compact 4.0 assemblies. In the examples below, this library folder is named SqlCompact.

Read more: Codeproject