0

I am trying to privately deploy SQL CE WPF with Entity Framework 6 using Code First.

On Development machine database generates fine in AppData folder and all works fine however on Testing PC I get an exception (no db):

"The ADO.NET provide with invariant name 'System.Data.SQlServerCe.40' is either not registered in the machine or application config file'

I've tried to implement all available literature regarding this issue but still has a problem. I've checked the Bin folder with Deployed Folder and it is the same, all libraries (x86 and amd64) are present and Project Platform target is x86.

  1. No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlServerCe.4.0'
  2. http://erikej.blogspot.dk/2013/11/entity-framework-6-sql-server-compact-4_25.html
  3. Entity Framewok Code First "ADO.NET provider not found" with local SQL Server CE DLL's

Bellow is my App.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>

  <entityFramework>
    <contexts>
      <context type="MyProject.DAL.GreatContext, MyProject">
        <databaseInitializer type="MyProject.Module.Database.Dal.GreatDbInitializer, MyProject" />
      </context>
    </contexts>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
    </providers>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>

  <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.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
    </DbProviderFactories>
  </system.data>


</configuration>

I also have added the bellow code but still issue remains :

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Any thoughts?

Community
  • 1
  • 1
Jim
  • 2,760
  • 8
  • 42
  • 66
  • What is the assembly version of the System.Data.SqlServerCe.dll included with your project? – ErikEJ Oct 16 '14 at 18:29

1 Answers1

2

Assuming you use version 4,0,0,1 of the ado.net provider, you need to use this assembly redirect:

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
    <bindingRedirect oldVersion="4.0.0.0-4.0.0.1" newVersion="4.0.0.1"/>
  </dependentAssembly>
</assemblyBinding>

Redirecting Entityframework.dll will not work.

And the proper solution is to use my EntityFramework.SqlServerCompact.PrivateDeployment NuGet package

ErikEJ
  • 40,951
  • 5
  • 75
  • 115
  • Hi Erik, I;ve tried that code also, and got the exception "The located assembly s manifest definition does not match the assebmly reference" on the Development pc. – Jim Oct 16 '14 at 18:42
  • Are you using assembly version 4,0,0,1? Some tips here http://stackoverflow.com/questions/215026/the-located-assemblys-manifest-definition-does-not-match-the-assembly-reference – ErikEJ Oct 16 '14 at 18:52
  • System.Data.SqlServerCe : Version 4.0.0.0, pls advice if I should upgrade ? I've added them through Nuget – Jim Oct 16 '14 at 19:00
  • Remove any assembly redirects, then, and make sure the System.Data.SqlServerCe.dll reference is set to Copy local and Copy always – ErikEJ Oct 16 '14 at 19:05
  • Hmm.. not sure what you mean by assembly redirects. I think this already done via nuget installer? in fact I can see that System.Data.SqlServerCe.dll is set to Copy Locak and I've checked taht System.Data.SqlServerCe.dll exist on Testing pc ... – Jim Oct 16 '14 at 19:06
  • And what happened then? (I will update/reissue my blog post...) – ErikEJ Oct 16 '14 at 19:06
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/63187/discussion-between-erikej-and-jim). – ErikEJ Oct 16 '14 at 19:11
  • I had the same issue and commenting this line out fixed it for SqlCe 3.5 – fanuc_bob Apr 17 '15 at 15:50