Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 657
Gaz83 Avatar asked Jan 26 '26 13:01

Gaz83


2 Answers

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!");
    }
}
like image 102
ErikEJ Avatar answered Jan 29 '26 03:01

ErikEJ


I updated SqlServerCe.dll reference from following path, and it fixed

Reference Path:

C:\Program Files\Microsoft SQL Server Compact Edition\v4.0\Desktop\System.Data.SqlServerCe.dll
like image 29
Saboor Awan Avatar answered Jan 29 '26 05:01

Saboor Awan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!