Search code examples
c#wpflinq-to-sqlsql-server-ce

SQL Server CE Incompatible Database Version


I have a SQL Server CE 4.0 database (.sdf file) and when I trying doing a query on the database from my application (WPF) I get the following error.

Incompatible Database Version. If this was a compatible file, run repair. For other cases refer to documentation. [ Db version = 4000000,Requested version = 3505053,File name = \?\C:\Database\ShortageReport\MRPDatabase.sdf]

  • I have checked SQL Server CE 4 sp1 is installed.
  • I have tried creating the database in both Database.Net 4 and in the connection setup in vs2012.
  • I'm running windows 7 64bit
  • My connection string is stored in the app.config.

I am using SQL Server Compact Toolbox to generate the context and the mappings.

My app.config:

<connectionStrings>
    <add name="DatabaseContext" 
         providerName="System.Data.SqlServerCe.4.0" 
         connectionString="Data Source=C:\Database\ShortageReport\MRPDatabase.sdf"/>
</connectionStrings>

Any ideas?


Solution

  • Add a reference to the version 4.0 System.Data.SqlServerCe.dll ADO.NET provider

    Then initialize the DataContext class with a SqlCeConnection (4.0) object.

    using (SqlCeConnection conn = new SqlCeConnection(@"Data Source=C:\projects\Chinook\Chinook40.sdf"))
    {
        using (Chinook db = new Chinook(conn))
        {
            var list = db.Album.ToList();
            if (list.Count > 0)
                System.Diagnostics.Debug.Print("It works!");
        }
    }