Share via


CompactDatabase Method (SQL Server Compact Edition)

The CompactDatabase method reclaims wasted space in the local SQL Server 2005 Compact Edition (SQL Server Compact Edition) database. This method can also be used to change the collating order, encryption, and password settings of the database.

Syntax

object.CompactDatabase(SourceConnection, DestConnection)

Parameters

Parameter Description

SourceConnection

A string value specifying a connection to the source database to be compacted. An error occurs if the database specified by SourceConnection is already open.

DestConnection

A string value specifying a connection to the destination database to be created by the compaction. An error occurs if the database specified by DestConnection already exists or another file with that name already exists.

Prototype

HRESULT CompactDatabase(BSTR SourceConnection, BSTR DestConnection);

Remarks

The SourceConnection and DestConnection parameters specify the properties of the source and destination databases. The following table lists the connection properties that you can specify for each parameter. All other connection properties are ignored.

Property Description

Provider

Indicates the name of the provider to use to connect to the data source. If this property is not specified, the OLE DB provider for SQL Server Compact Edition is assumed. An error occurs if the name of the provider in the source string is different from the name of the provider in the destination string.

Data Source

Indicates the name of the database. This property is required for both the source and destination connection information.

Locale Identifier

Indicates the locale identifier (LCID) for the new database. If this is omitted, the destination database will have the same LCID as the system locale.

Locale Identifier specifies the collating order for string comparisons in the database.

SSCE:Database Password

Indicates the password, if the database is secured by a password. The source database password must be supplied if the source database contains a password. If this parameter is omitted from the DestConnection string, the new database will have the same database password as the source database. If you want to remove the password from the destination database, the database password must be set to an empty string. The database password can be up to 40 characters long.

SSCE:Encrypt Database

Indicates whether to encrypt the new database. If this parameter is omitted from the DestConnection string, the new database will have the same encryption as the source database. This is a Boolean value and should be set to TRUE for encryption or FALSE for no encryption.

Note

If SSCE:Database Password is specified, the database is always encrypted, regardless of whether SSCE:Encrypt Database is specified.

SSCE:Temp File Directory

Specifies the location of the temporary database. If this parameter is omitted from the DestConnection string. Then the current database location is used as the location of the temporary database.

Locale identifier values are supported. Use the unique LCID for the value of Locale Identifier. To find a list of unique LCID values, see COLLATE (SQL Server Compact Edition). You must ensure that the locale is supported on the device on which the database is being created.

If you do not specify an LCID value when you create the database, SQL Server Compact Edition uses the system locale. This differs from earlier versions, which always used the English locale if none was supplied.

See Also

Reference

ErrorRecords Property (SQL Server Compact Edition)

Other Resources

SQL Server Compact Edition Engine Object Programming

Help and Information

Getting SQL Server Compact Edition Assistance