Creating Databases with OLE DB
The OLE DB provider for SQL Server 2005 Compact Edition (SQL Server Compact Edition) reveals the IDBDataSourceAdmin interface through which you can create and manage databases in SQL Server Compact Edition.
Creating a Database
To create a new database, you must specify the DBPROP_INIT_DATASOURCE property to specify a name for the database. For security reasons, the OLE DB provider for SQL Server Compact Edition does not support deleting databases by using IDBDataSourceAdmin::DestroyDataSource. If you want to delete a database and you have access to the file system on the computer, you can delete the database files that are no longer needed.
Securing Databases
For improved security, SQL Server Compact Edition supports creating both password-protected and encrypted databases. Encrypted databases must also be password-protected. Data in a password-protected or encrypted database can be accessed by SQL Server Compact Edition only after the correct password has been provided.
Note
If you forget the password for an encrypted database, the data cannot be recovered and remains inaccessible.
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. The following table summarizes the properties that must be specified to create each type of database.
Type of database to create | Required properties |
---|---|
Standard database |
DBPROP_INIT_DATASOURCE |
Password-protected database |
DBPROP_INIT_DATASOURCE DBPROP_SSCE_DBPASSWORD |
Encrypted database |
DBPROP_INIT_DATASOURCE DBPROP_SSCE_DBPASSWORD DBPROP_SSCE_ENCRYPTDATABASE |
For an existing database, these properties can be changed when the database is compacted. For more information, see CompactDatabase Method (SQL Server Compact Edition).
Examples
For an example of creating a database with the OLE DB provider for SQL Server Compact Edition, see How to: Create a Database by Using OLE DB (Programmatically).