LocalConnectionString Property (SQL Server Compact Edition)

Provides the connection string for the local Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) database.




Part Description


A SQL Server Compact Edition Engine object




The LocalConnectionString property can be set only when the connection is closed. Many of the connection string values have corresponding read-only properties. When the connection string is set, all these properties are updated, except when an error is detected. In this case, none of the properties is updated.

Resetting the LocalConnectionString on a closed connection resets all connection string values and related properties, including the password.

The following table lists the LocalConnectionString properties supported in SQL Server Compact Edition.



data source

File path and name of the SQL Server Compact Edition database.


You should specify the absolute path of the database file, instead of a relative path.

ssce: database password

The database password, which can be up to 40 characters in length. If not specified, the default value is no password. This property is required if you enable encryption on the database. If you specify a password, encryption is enabled on the database.

ssce: encrypt database

A Boolean value that determines whether the database is encrypted. Must be set to true to enable encryption or false for no encryption. If not specified, the default value is false. If you enable encryption, you must also specify a password with the password property. If you specify a password, encryption is enabled regardless of how you set this property.

ssce: max buffer size

The largest amount of memory, in KB, that SQL Server Compact Edition can use before it starts flushing changes to disk. If not specified, the default value is 640.

ssce: max database size

The maximum size of the database, in MB. If not specified, the default value is 128.


The mode to use when you open the database file. For valid values, see the table that follows. If not specified, the default value is Read/Write.

ssce: default lock timeout

The default number of milliseconds that a transaction will wait for a lock. If not specified, the default value is 2000.

ssce: default lock escalation

The number of locks a transaction will acquire before you try escalation from row to page, or from page to table. If not specified, the default value is 100.

ssce: flush interval

Specifies the interval time in seconds before all committed transactions are flushed to disk. If not specified, the default value is 10.

ssce: autoshrink threshold

The percent of free space in the database file that is permitted before autoshrink begins. A value of 100 disables autoshrink. If not specified, the default value is 60.

ssce: temp file directory

The location of the temporary database. If not specified, the default is to use the database specified in the data source property for temporary storage.

ssce: temp file max size

The maximum size of the temporary database file, in Megabytes. If not specified, the default value is 128.

locale identifier

The locale ID (LCID) to use with the database.

The following table shows valid values for the mode property of the connection string.



Read Write

Lets multiple processes open and modify the database. This is the default setting if the mode property is not specified.

Read Only

Lets you open a read-only copy of the database.


Does not let other processes to open or modify the database.

Shared Read

Lets other processes read, but not modify, the database while you have it open.

The following rules apply to connection strings:

  1. All blank characters, except those within a value or within quotation marks, are ignored.

  2. Keyword value pairs must be separated by a semicolon (;). If a semicolon is part of a value, it also must be delimited by quotation marks.

  3. No escape sequences are supported.

  4. The value type is irrelevant.

  5. Names are not case-sensitive.

  6. If a property name occurs more than one time in the connection string, the value associated with the last occurrence is used.

  7. Values can be delimited by single or double quotation marks, for example, name='value' or name="value". Either single or double quotation marks can be used within a connection string by using the other delimiter. For example, the following are valid uses of quotation marks within a connection string:

    "data source='MyDb.sdf'; ssce: mode=Exclusive;"
    'data source="MyDb.sdf"; ssce: mode=Exclusive;'
    But these examples are not valid:
    "data source="MyDb.sdf"; ssce: mode=Exclusive;"
    'data source='MyDb.sdf'; ssce: mode=Exclusive;'

See Also


SSCEError Object
CompactDatabase Method (SQL Server Compact Edition)
SSCEErrors Collection

Help and Information

Getting SQL Server Compact Edition Assistance