The Database Engine for SQL Server Compact 3.5 lets you encrypt databases. Databases that are encrypted are also protected with a database password.

Because encrypted databases can only be accessed with a password, if the password for an encrypted database is lost, the data is unrecoverable.

You can specify the type of encryption used to encrypt the database by setting the connection string attribute, Encryption Mode, to one of the available encryption modes: Platform Default, Engine Default, or PPC2003 Compatibility.

Creating Encrypted Databases

You can create encrypted databases by supplying both encryption and password properties when the database is created. Encrypted databases can be created by the following methods:

  • Using SQL syntax

    To create an encrypted database by using SQL syntax, specify both database_password and the ENCRYPTION ON option. For example:

    Create Database "secure.sdf" databasepassword '<password>' encryption on
    
  • Using the .NET Compact Framework Data Provider

    To create a password-protected database by using the SqlCeEngine.CreateDatabase method, you must specify the password property in the connection string. For example:

    "data source=\secure.sdf;password=<enterStrongPasswordHere>;encrypt database=TRUE"
    

    For more information, see the System.Data.SqlServerCe.SqlCeEngine class in the Microsoft Visual Studio documentation.

  • Using OLE DB

    To create an encrypted database by using the OLE DB provider for SQL Server Compact 3.5, you must pass the provider-specific property DBPROP_SSCE_ENCRYPTDATABASE as VARIANT_TRUE and specify a password by using the provider-specific property DBPROP_SSCE_DBPASSWORD.

Accessing Encrypted Databases

A password must be supplied to open an encrypted database. Encrypted databases can be accessed by the following methods:

  • Using the data provider for SQL Server Compact 3.5

    To access a password-protected database by using the SqlCeConnection.Open method, you must specify the password property in the connection string. For example:

    "data source=ssce.sdf; password=<enterStrongPasswordHere>"
    

    For more information, see the System.Data.SqlServerCe.SqlCeConnection class in the Visual Studio documentation.

  • Using OLE DB

    To open a password-protected database in OLE DB, you must specify the provider-specific property DBPROP_SSCE_DBPASSWORD.

Tasks

How to: Secure a Database (SQL Server Management Studio)