Search code examples
c#sql-server-ce

SQL Server CE: Suppress modifications of database file?


we have an application that has a local SQL Server CE database file. When we open the database, but don't do any changes to it, the database file is changed anyway:

using (var connection = new SqlCeConnection("Data Source='data.sdf';File Mode='Shared Read';Encrypt=FALSE;LCID=1033"))
{
    connection.Open();
    using (var context = new DataContext(connection))
    {
    }
}

This changes some bytes at the very beginning of the sdf-file.

Is there any way to prevent this?


Solution

  • Yes, you can enable read only mode in the connection string. Also you may need to specify a temp path in this case:

    string connectionString = ...;Mode = Read Only;Temp Path= ...; 
    

    More info.