Share via


Encrypting a Database

The Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) Database Engine lets you encrypt databases. Databases that are encrypted are also protected with a database password.

Important

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

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=<myPassword>;encrypt database=TRUE"
    

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

  • Using OLE DB
    To create an encrypted database by using the OLE DB provider for SQL Server Compact Edition, 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 Edition
    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=<myPassword>"
    

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

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

See Also

Tasks

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

Help and Information

Getting SQL Server Compact Edition Assistance