11/06/2010 17:55:22

The most up-to-date version of this file is available online at the Microsoft Download Center

The SQL Server documentation team welcomes your documentation feedback. We view and investigate all documentation issues but do not answer technical support questions here. For help with technical issues not related to documentation, see Getting Assistance with SQL Server Compact. If it is possible, submit feedback to us in English.

Contents

1.0 Introduction

Microsoft® SQL Server™ Compact 4.0 is a small footprint, in-process database engine that allows developers to build robust applications for Windows desktop computers and for starter ASP.NET websites.

1.1 Obtaining SQL Server Compact 4.0

SQL Server Compact 4.0 is available from the following Web download:

Important

The installation behavior of SQL Server Compact 4.0 on 32-bit and 64-bit operating systems has changed as compared to the previous versions of SQL Server Compact. The installation of SQL Server Compact 4.0 on 32-bit and 64-bit operating systems is as given below:

Version

Operating system

Result

32-bit, SQL Server Compact 4.0

32-bit

Successful

64-bit, SQL Server Compact 4.0

64-bit

Successful

32-bit, SQL Server Compact 4.0

64-bit

Error

64-bit, SQL Server Compact 4.0

32-bit

Error

[Return to Contents]

1.2 SQL Server Compact 4.0 Books Online

2.0 Supported Operating Systems and Platforms for SQL Server Compact 4.0

SQL Server Compact 4.0 supports the following operating systems.

Windows Desktop Computers

  • Microsoft Windows XP Professional SP3

  • Microsoft Windows XP Home Edition SP3

  • Microsoft Windows XP Media Center Edition 2004 SP3

  • Microsoft Windows XP Media Center Edition 2005

  • Microsoft Windows XP Tablet PC Edition SP3

  • Microsoft Windows XP Embedded SP3

  • Microsoft Windows XP Professional x64 SP3

  • Windows Embedded for Point of Service SP3

  • Microsoft Windows Server 2003, Standard Edition SP2

  • Microsoft Windows Server 2003, Enterprise Edition SP2

  • Microsoft Windows Server 2003, Datacenter Edition SP2

  • Microsoft Windows Server 2003 R2, Standard Edition

  • Microsoft Windows Server 2003 R2, Enterprise Edition

  • Microsoft Windows Server 2003 R2, Datacenter Edition

  • Microsoft Windows Server 2003 x64, Standard Edition

  • Microsoft Windows Server 2003 x64, Enterprise x64 Edition

  • Microsoft Windows Server 2003 x64, Datacenter Edition

  • Microsoft Windows Server 2003 R2 x64, Standard Edition

  • Microsoft Windows Server 2003 R2 x64, Enterprise Edition

  • Microsoft Windows Server 2003 R2 x64, Datacenter Edition

  • Windows Vista Home Basic SP2

  • Windows Vista Home Premium SP2

  • Windows Vista Business SP2

  • Windows Vista Enterprise SP2

  • Windows Vista Ultimate SP2

  • Windows Vista Starter Edition SP2

  • Windows Vista Home Basic x64 SP2

  • Windows Vista Home Premium x64 SP2

  • Windows Vista Business x64 SP2

  • Windows Vista Enterprise x64 SP2

  • Windows Vista Ultimate x64 SP2

  • Windows Server 2008 Standard Server SP2

  • Windows Server 2008 Standard Server SP2 (without Hyper-V)

  • Windows Server 2008 Enterprise SP2

  • Windows Server 2008 Enterprise SP2 (without Hyper-V)

  • Windows Server 2008 Data Center SP2

  • Windows Server 2008 Data Center SP2 (without Hyper-V)

  • Windows Server 2008 Web Edition SP2

  • Windows Server 2008 Standard Server SP2 x64

  • Windows Server 2008 Standard Server SP2 x64 (without Hyper-V)

  • Windows Server 2008 Enterprise SP2 x64

  • Windows Server 2008 Enterprise SP2 x64 (without Hyper-V)

  • Windows Server 2008 Data Center SP2 x64

  • Windows Server 2008 Data Center SP2 x64 (without Hyper-V)

  • Windows Server 2008 Web Edition SP2 x64

  • Windows 7 Starter

  • Windows 7 Starter x64

  • Windows 7 Home Premium

  • Windows 7 Home Premium x64

  • Windows 7 Professional

  • Windows 7 Professional x64

  • Windows 7 Ultimate

  • Windows 7 Ultimate x64

  • Windows Server 2008 R2 Foundation x64

  • Windows Server 2008 R2 Standard x64

  • Windows Server 2008 R2 Enterprise x64

  • Windows Server 2008 R2 Datacenter x64

  • Windows Web Server 2008 R2 x64

.NET Framework

3.0 Known Issues

3.1

3.2

If the SQL Server Compact Runtime installer is run on a machine which does not have a .Net Framework installed, the installation proceeds without any errors but there are a few steps which are not performed. It may cause errors on such a machine. The steps which are not performed are:

  • The machine.config entry for .NET would not have entry for SQL Server Compact as a data provider.

  • The relevant assemblies of Compact runtime are not put in the Global Assembly Cache.

This can also happen if a user performs the following steps:

  • Install SQL Server Compact 4.0 runtime

  • Install .NET Framework 3.5 SP1 or 4.0

To solve this problem, Reinstall / Repair SQL Server Compact runtime post .NET Framework installation.

3.3

SQL Server Compact 4.0 does not recognize the Encrypt property of the SqlCeConnection class, and you should not use this property to encrypt database files.

Note

The Encrypt property was deprecated in SQL Server Compact v3.5 release. This property was retained in SQL Server Compact 4.0 only for backward compatibility.

Use the Encryption Mode property of the SqlCeConnection class to encrypt SQL Server Compact 4.0 database files. The following examples show uses of the Encryption Mode property.

  • To create a new encrypted SQL Server Compact 4.0 database:

    C#:

     
    SqlCeEngine engine = new SqlCeEngine("Data Source=Northwind.sdf;encryption mode=platform default;Password=<enterStrongPasswordHere>;");
    engine.CreateDatabase();

    Visual Basic:

     
    Dim engine As SqlCeEngine = New SqlCeEngine("Data Source=Northwind.sdf;encryption mode=platform default;Password=<enterStrongPasswordHere>;")
    engine.CreateDatabase()
  • To change the encryption mode of an existing SQL Server Compact 4.0 database:

    C#:

     
    SqlCeEngine engine = new SqlCeEngine("Data Source=Northwind.sdf;Password=<enterStrongPasswordHere>;");
    engine.Compact("Data Source=Northwind.sdf;encryption mode= enginedefault;Password=<enterStrongPasswordHere>;");

    Visual Basic:

     
    Dim engine As SqlCeEngine = New SqlCeEngine("Data Source=Northwind.sdf;Password=<enterStrongPasswordHere>;") 
    engine.Compact("Data Source=Northwind.sdf;encryption mode= engine default;Password=<enterStrongPasswordHere>;")
  • To encrypt an unencrypted SQL Server Compact 4.0 database:

    C#:

     
    SqlCeEngine engine = new SqlCeEngine("Data Source=Northwind.sdf");
    engine.Compact("Data Source=Northwind.sdf;encryption mode=platform default;Password=<enterStrongPasswordHere>;");

    Visual Basic:

     
    Dim engine As SqlCeEngine = New SqlCeEngine("Data Source=Northwind.sdf;") 
    engine.Compact("Data Source=Northwind.sdf;encryption mode=platform default;Password=<enterStrongPasswordHere>;"

3.4

SQL Server Compact 4.0 data types for parameters like SqlDbType or DbType should be explicitly set.

If the data types for parameters such as SqlDbType or DbType are not explicitly set, an exception is be thrown. To resolve this issue, explicitly set the data type for parameters such as SqlDbType or DbType. This is critical in the case of BLOB data types (image and ntext). A code example is given below:

C#:

 
SqlCeEngine engine = new SqlCeEngine(connString);
engine.CreateDatabase();
engine.Dispose();

SqlCeConnection conn = new SqlCeConnection(connString);
conn.Open();

SqlCeCommand cmd = conn.CreateCommand();
cmd.CommandText = "CREATE TABLE BlobTable(name nvarchar(128), blob ntext);";
cmd.ExecuteNonQuery();

cmd.CommandText = "INSERT INTO BlobTable(name, blob) VALUES (@name, @blob);";
SqlCeParameter paramName = cmd.Parameters.Add("name", SqlDbType.NVarChar, 128);
SqlCeParameter paramBlob = cmd.Parameters.Add("blob", SqlDbType.NText);
paramName.Value = "Name1";
paramBlob.Value = "Name1".PadLeft(4001);

cmd.ExecuteNonQuery();

Visual Basic:

 
Dim engine As SqlCeEngine = New SqlCeEngine(connString)
engine.CreateDatabase()
engine.Dispose()

Dim conn As SqlCeConnection = New SqlCeConnection(connString)
conn.Open()

Dim cmd As SqlCeCommand = conn.CreateCommand()
cmd.CommandText = "CREATE TABLE BlobTable(name nvarchar(128), blob ntext);"
cmd.ExecuteNonQuery() 

cmd.CommandText = "INSERT INTO BlobTable(name, blob) VALUES (@name, @blob);"
Dim paramName As SqlCeParameter
Dim paramBlob As SqlCeParameter
paramName = cmd.Parameters.Add("name", SqlDbType.NVarChar, 128)
paramBlob = cmd.Parameters.Add("blob", SqlDbType.NText)
paramName.Value = "Name1"
paramBlob.Value = "Name1".PadLeft(4001)

cmd.ExecuteNonQuery()

3.5

The SQL Server Compact 4.0 release does not support syncing of data with SQL Server using technologies like Microsoft Sync Framework, or merge replication, or remote data access (RDA).

3.6

The generation of the Entity Data Model for SQL Server Compact will fail if there are duplicate constraint names in the SQL Server Compact schema.

In SQL Server Compact, the constraint names are unique within a table and this can allow duplicate constraint names in the database. The behavior is different from SQL Server, where the constraint names are unique across the database. If a SQL Server Compact schema has duplicate referential integrity (primary key – foreign key relationship) constraint names, the generation of the Entity Data Model using the ADO.NET Entity Framework’s Entity Data Model Wizard will fail. The workaround is to change the name of the duplicate constraint name to be unique across the database, like by adding the name of the table to the constraint name.

[Return to Contents]

4.0 Additional Information