How to: Set the File Mode When Opening a Database (Programmatically)
In this topic, you will learn how to set the file mode when you open a Microsoft SQL Server 2005 Compact Edition (SQL Server Compact Edition) database. To set the mode in which the database is opened, you use the mode property in the connection string. The following table defines the valid values for the file mode:
Value | Definition |
---|---|
Read/Write |
Permits multiple processes to open and modify the database. |
Read Only |
Lets you open a read-only copy of the database. |
Exclusive |
Does not permit other processes to open or modify the database. |
Shared Read |
Permits other processes to read, but not modify, the database while you have it open. |
Note
If you are opening a database that is located on a file share, use the Exclusive file mode.
To open the database exclusively
When you access the SQL Server Compact Edition database, set the mode property in the connection string to Read/Write, Read Only, Exclusive, or Shared Read. For example, you can set the ConnectionString property of a SqlCeEngine object to ensure an exclusive lock on the database until the SqlCeEngine object is destroyed.
SqlCeEngine eng = new SqlCeEngine(); eng.LocalConnectionString="Data Source=MyDatabase.sdf; " + "Mode = Exclusive";
See Also
Other Resources
Working with Databases (SQL Server Compact Edition)
Maintaining Databases (SQL Server Compact Edition)
Accessing and Modifying Databases (SQL Server Compact Edition)