Export (0) Print
Expand All

SqlCeConnection.ConnectionString Property

Gets or sets the string used to open a database.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)

public override string ConnectionString { get; set; 
/** @property */
public String get_ConnectionString ()

/** @property */
public void set_ConnectionString (String value)

public override function get ConnectionString () : String

public override function set ConnectionString (value : String)

Property Value

The .NET Compact Framework Data Provider for SQL Server Mobile connection string that includes the data source name and other parameters needed to establish the initial connection. The default value is an empty string.

Exception typeCondition

ArgumentException

An invalid connection string argument has been supplied.

The ConnectionStringproperty 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 of these properties are updated, except when an error is detected. In this case, none of the properties is updated. SqlCeConnection properties return only those settings contained in the ConnectionString.

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

The following table lists the ConnectionStringproperties supported in SQL Server Mobile. For more information, see the SQL Server Mobile Books Online.

data source

The file path and name of the SQL Mobile 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 automatically enabled on the database.

encrypt

A Boolean value that determines whether or not 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.

max buffer size

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

max database size

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

mode

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

default lock timeout

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

default lock escalation

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

flush interval

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

autoshrink threshold

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

temp path

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.

temp file max size

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

persist security info

When set to false (which is strongly recommended), security-sensitive information, such as the password, is not returned as part of the connection if the connection is open or has ever been in an open state. Resetting the connection string resets all connection string values, including the password. The default value is false.

locale identifier

The locale ID (LCID) to use with the database. Valid LCID values are listed in the CultureInfo class.

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

Read Write

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

Read Only

Allows you to open a read-only copy of the database.

Exclusive

Does not allow other processes from opening or modifying the database.

Shared Read

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

A preliminary validation of the connection string is performed when the property is set. When an application calls the Open method, the connection string is fully validated. If the connection string contains properties that are unsupported or not valid, a run-time exception, such as ArgumentException, is generated at that time.

The following rules apply to connection strings:

  1. All blank characters, except those placed 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 once 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'; mode=Exclusive;"
    'data source="MyDb.sdf"; mode=Exclusive;'
    

    But these examples are not valid:

    "data source="MyDb.sdf"; mode=Exclusive;"
    'data source='MyDb.sdf'; mode=Exclusive;'
    

The following example creates a SqlCeConnection and sets some of its properties in the connection string.

SqlCeConnection conn = new SqlCeConnection();

// Set some connection string properties e.g.:
// 
conn.ConnectionString = 
    "Persist Security Info = False; Data Source = 'SalesData.sdf';" +
    "Password = '<password>'; File Mode = 'shared read'; " +
    "Max Database Size = 256; Max Buffer Size = 1024";

conn.Open();

// You can change the database while preserving 
// the orignal connection options
//
conn.ChangeDatabase("SupportData.sdf");

  • Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see .

Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft