Vojtěch Dohnal
Vojtěch Dohnal

Reputation: 8104

SQL Server Compact 4.0 private deployment with Entity Framework 6.0 and NuGet

I have standardly setup WPF project with Entity Framework 6 and SQL Server Compact 4.0 installed. When I build my project all the necessary files for SQL Server CE deployment are correctly copied to the Release folder, including System.Data.SqlServerCe.dll.

But running project on a machine without SQL Server Compact installed throws System.IO.FileLoadException.

In my development environment is the System.Data.SqlServerCe.dll loaded from GAC. I have found this reference, where the version numbers of dlls are explained: http://technet.microsoft.com/en-us/library/gg213826.aspx

I supposed that the version of System.Data.SqlServerCe.dll assembly form NuGet is 4.0.0.0.

So I have manually changed System.Data.SqlServerCe.dll reference in my project to 4.0.0.1 file form the Private folder and copied System.Data.SqlServerCe.dll 4.0.0.1 to the production machine.

I have changed app.config like that:

  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SqlServerCe.4.0" />
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
    </DbProviderFactories>
  </system.data>

Now I get this exception on development machine:

The connection given is not of type 'SqlCeConnection'.

On production machine I get System.Data.Entity.Core.EntityException.

Is there any chance to get private deployment working with NuGet and EF 6? Or is it necessary to copy manually all the files in x86, amd64 folders?

Upvotes: 0

Views: 3887

Answers (1)

Vojtěch Dohnal
Vojtěch Dohnal

Reputation: 8104

The System.Data.Entity.Core.EntityException was already problem within my app, I also forgot to change DB name after deployment.

I have followed this guide and it is working now:

http://erikej.blogspot.sk/2013/11/entity-framework-6-sql-server-compact-4_25.html

Upvotes: 0

Related Questions