Export (0) Print
Expand All

SqlCeConnection.ChangeDatabase Method

Changes the current database for an open SqlCeConnection.

Namespace:  System.Data.SqlServerCe
Assembly:  System.Data.SqlServerCe (in System.Data.SqlServerCe.dll)

public override void ChangeDatabase(
	string value


Type: System.String
The database name.




The database name is not valid.


The connection is not open.


The databases cannot be changed.

The name supplied in the value parameter must be a valid database name. The name must be the full path to the database; for example, "\my app\myDB.sdf". The value parameter cannot be null, be empty, or contain a string with only blank characters.

ChangeDatabase applies to the new database the same properties used to open the current database, except for the password, which will be set to an empty string.

If the new database requires a password, this call will fail. If this occurs, to change databases, you must close the original connection, specify a new connection string, and then reopen the connection.

The following example shows how to switch databases while preserving the original connection options.

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";


// You can change the database while preserving 
// the orignal connection options

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft