The database file has been created by an earlier version of SQL Server Compact

Problem

You get this error when running your application:

The database file has been created by an earlier version of SQL Server Compact. Please upgrade using SqlCeEngine.Upgrade() method.

In your application, you are allowed to use either Microsoft SQL CE 3.5 or 4.0 but not both.  If your application is set to used Microsoft SQL CE 4.0, the following will be present in the web.config

<dependentAssembly>

            <assemblyIdentity name="System.Data.SqlserverCe" publicKeyToken="89845dcd8080cc91"/>

            <bindingRedirect oldVersion="3.5.1.0" newVersion="4.0.0.0"/>

</dependentAssembly>

… in this section of Web.config:

<runtime>

            <assemblyBinding …>

In this case, if your application attempts to connect a 3.5 CE database, you will get this error.

Solution

Convert your databases to be either Microsoft SQL CE 3.5 or 4.0 so that they all have the same version.   Then, select “Databases->Synchronization Database Schema”   If your application uses Microsoft SQL CE 3.5 database files, make sure Microsoft SQL CE 3.5 is installed in your system.  If your application uses Microsoft SQL CE 4.0 database files, make sure Microsoft SQL CE 4.0 is installed in your system that can be downloaded from http://www.microsoft.com/download/en/details.aspx?id=17876.

See Also

Part VII:  Troubleshooting Applications

Application Will Not Run

Application Runs But No Data is Displayed

Application Error Messages