PAVE OVER SQL Server Compact 4.0 and Visual Studio
Microsoft SQL Server Compact 4.0 (SQL Server Compact 4.0) enables you to create compact databases that can be deployed on desktop computers, smart devices, and Tablet PCs.
When you build applications that use SQL Server Compact, you can use one of the Microsoft .NET programming languages (Microsoft Visual Basic or Microsoft Visual C#) and the .NET Framework or .NET Compact Framework to create a managed application. Or you can use Microsoft Visual C++ or Visual C++ for Devices to create a native application.
When you create applications, the preferred local database is SQL Server Compact. For more information about incorporating a database as part of an application, see Local Data Overview.
The choice of whether to create a managed or native application depends on your needs and current skills. Developers who are familiar with Microsoft Visual C++ programming and who need more control over system resources can create a native application by using Visual C++. Developers who are already developing Microsoft Windows-based or web applications by using the .NET Framework, and those who are familiar with one of the .NET programming languages, should consider creating managed applications to take advantage of the features of the .NET Framework for desktop computers and Tablet PCs or of the .NET Compact Framework for smart devices.
SQL Server Compact 4.0 Components
By default, SQL Server Compact 4.0 documentation is not installed locally. To download SQL Server Compact 4.0 Books Online, go to the SQL Server Compact 4.0 Books Online Download Center.
SQL Server Compact 4.0 components are available in three Microsoft Windows Installer (.msi) files:
SSCE 4.0 Design Tools (SSCEVSTools-ENU.msi)
This file installs the SQL Server Compact 4.0 design-time components with Visual Studio. The design-time components are the user interface, dialog boxes, and design-time environment, which are used to write applications for SQL Server Compact 4.0. The SQL Server Compact 4.0 design-time components will be installed under the directory Program Files\Microsoft Visual Studio 10.0\Common7\IDE\. These components are bundled with Visual Studio and cannot be shipped independently of Visual Studio. SQL Server Compact 4.0 samples and SQL Server Compact 4.0 header files (for native development) are also installed by this .msi file.
SQL Server Compact 4.0 (SSCERuntime_x64-ENU.msi or SSCERuntime_x86-ENU.msi)
This file installs the SQL Server Compact 4.0 runtime components for desktop computers and Tablet PCs in a central folder: Program Files\Microsoft SQL Server Compact Edition\v4.0. The SQL Server Compact 4.0 desktop and Tablet PC runtime components are required for developing applications in Visual Studio and for running SQL Server Compact 4.0-based applications on the desktop. This .msi file also installs the following:
- Microsoft Synchronization Services for ADO.NET components. The Microsoft Synchronization Services for ADO.NET components are installed at Program Files\Microsoft Synchronization Services\ADO.NET\v1.0.
SQL Server Compact 4.0 for Devices (SSCEDeviceRuntime-ENU.msi)
This file installs the runtime components for SQL Server Compact 4.0 devices in Program Files\Microsoft SQL Server Compact Edition\v4.0\Devices. The runtime components are required for developing Windows Mobile and Windows CE device-based applications in Visual Studio and for deploying the applications on mobile devices.
Notable Features in SQL Server Compact
SQL Server Compact provides the following features to consider when you are using it as the local data store for your applications.
SQL Server Compact is file based, which means that the connection string is a file path to the database (.sdf) file.
SQL Server Compact does not run as a service. This is one of the main differences between using SQL Server Compact and using SQL Server or SQL Server Express Edition.
SQL Server Compact supports multiple connections up to the 256 connection limit. Opening connections on different processes is also supported.
The current version of SQL Server Compact supports database files up to 4 GB.
When to Use SQL Server Compact
SQL Server Compact is a file-based database that consists of DLLs that are approximately 1.4 MB.
The following list provides some scenarios in which you might want to use SQL Server Compact in your applications:
For applications intended for desktop computers and mobile devices. For more information, see PAVE OVER Walkthrough: Adding a SQL Server Compact Database to an Application and Deploying it.
When you need a database that is free to redistribute.
When application size and memory requirements must be compact.
When you want the data access code to run in a process.
SQL Server Compact 4.0 provides two deployment models that you can incorporate into your applications.
You can use the traditional Microsoft setup technology, including ClickOnce deployment. You can also use a file-based deployment in which you add the SQL Server Compact 4.0 DLLs and deploy them with your project.
Data Directory Support
SQL Server Compact 4.0 supports the Data Directory macro. This means that if you add the string |DataDirectory| (enclosed in pipe symbols) to a file path, it will resolve to the path of the database.
For example, consider the connection string:
"Data Source= c:\program files\MyApp\Mydb.sdf"
When using Data Directory, you can instead use the following connection string:
"Data Source = |DataDirectory|\Mydb.sdf"
For more information, see PAVE OVER How to: Deploy a SQL Server Compact 4.0 Database with an Application.
Database Upgrades and Backward Compatibility
SQL Server Compact 4.0 can be installed together with the previous version (3.5), on desktop and Tablet PC computers. If you try to open database files created by earlier versions, you will receive a message stating that the file cannot be opened. To open it, you must first upgrade the database file by using the Upgrade SQL Server Compact database dialog box in Visual Studio. To access the Upgrade SQL Server Compact database dialog box, complete the Add Connection dialog box, which is accessed from the Data Connections node in Server Explorer. The file name extension for SQL Server Compact 4.0 files is .sdf, which is the same as that of the earlier versions.
When a database file is upgraded to SQL Server Compact 4.0, you will no longer be able to open the database file by using the earlier versions of the SQL Server Compact engine.
SQL Server Compact 4.0 Books Online
By default, SQL Server Compact documentation is not installed locally. To download SQL Server Compact 4.0 Books Online, go to the SQL Server Compact 4.0 Books Online Download Center. SQL Server Compact Books Online provides conceptual and programming information about how to develop, administer, and deploy SQL Server Compact applications on desktop computers, mobile devices, and Tablet PCs.
64 Bit Development
For 64-bit development with Visual Studio and SQL Server Compact 4.0, the Target CPU option in the Advanced Compiler Settings must be explicitly set to x86. When the Target CPU is set to the default value of Any CPU an "Unable to load sqlceme40.dll" message might be encountered. Set the Target CPU option in the Advanced Compiler Settings in project properties.