ASP.NET MVC 4 + Entity Framework 6 + SQL Compact Edition 4.0 deployment no install


Question

Im trying to deploy a basic MVC 4 app that uses Entity Framework 6 (Code First) and SQL Compact 4.0 on a clean install of windows 7 with iis installed (mvc 4 and sql compact 4.0 is not installed).

I got the following nuget packages installed on the db project:

  • EntityFramework (Version 6.0.0-alpha2)
  • EntityFramework.SqlServerCompact (Version 6.0.0-alpha2)
  • Microsoft.AspNet.Providers (Version 1.2)
  • Microsoft.AspNet.Providers.Core (Version 1.2)
  • Microsoft.SqlServer.Compact (Version 4.0.8876.1)

In web.config i got the following config:

<connectionStrings>
  <add name="[Name]" connectionString="Data Source=|DataDirectory|[FileName].sdf" providerName="System.Data.SqlServerCe.4.0" />
</connectionStrings>  

......................

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
     <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
     </parameters>
  </defaultConnectionFactory>
  <providers>
      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  </providers>
</entityFramework>

Bin folder (sql ce files are in amd64 and x86 folder:

  • [amd64]
  • [x86]
  • Antlr3.Runtime.dll
  • DotNetOpenAuth.AspNet.dll
  • DotNetOpenAuth.Core.dll
  • DotNetOpenAuth.OAuth.Consumer.dll
  • DotNetOpenAuth.OAuth.dll
  • DotNetOpenAuth.OpenId.dll
  • DotNetOpenAuth.OpenId.RelyingParty.dll
  • EntityFramework.dll
  • EntityFramework.SqlServer.dll
  • EntityFramework.SqlServer.xml
  • EntityFramework.SqlServerCompact.dll
  • EntityFramework.SqlServerCompact.xml
  • EntityFramework.xml
  • Microsoft.Web.Infrastructure.dll
  • Microsoft.Web.WebPages.OAuth.dll
  • Newtonsoft.Json.dll
  • ShipMedProto.DB.dll
  • ShipMedProto.DB.pdb
  • ShipMedProto.Web.dll
  • ShipMedProto.Web.pdb
  • System.ComponentModel.DataAnnotations.dll
  • System.Data.DataSetExtensions.dll
  • System.Data.SqlServerCe.dll
  • System.Data.SqlServerCe.Entity.dll
  • System.Net.Http.Formatting.dll
  • System.Web.Helpers.dll
  • System.Web.Http.dll
  • System.Web.Http.WebHost.dll
  • System.Web.Mvc.dll
  • System.Web.Optimization.dll
  • System.Web.Providers.dll
  • System.Web.Razor.dll
  • System.Web.WebPages.Deployment.dll
  • System.Web.WebPages.dll
  • System.Web.WebPages.Razor.dll
  • WebActivatorEx.dll
  • WebGrease.dll
  • WebMatrix.Data.dll
  • WebMatrix.WebData.dll

When I deploy to the clean machine I get the following error message:

Unable to find the requested .Net Framework Data Provider. It may not be installed.

On my dev machine it is working fine. (I got sql ce installed)

Any clue what Im doing wrong?

Popular Answer

I think what you really want to do is manage the NuGet packages such that you add SqlServerCompact support for EntityFramework. Just right click your references and Manager NuGet packages. Then in the dialog do a search for SqlServerCompact. You SHOULD see this:

enter image description here

Adding this should add the equivalent strings that were in the answer above. I ended up with this in the web.config (or app.config if you're doing an app)

    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="System.Data.SqlServerCe.4.0" />
          </parameters>
        </defaultConnectionFactory>
        <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>   
</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>

Sorry, I'm about a year late but hopefully this helps someone else.





Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why