Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 447
oskarkvamme Avatar asked Feb 19 '13 11:02

oskarkvamme


2 Answers

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.

like image 53
Louis Duran Avatar answered Oct 22 '22 07:10

Louis Duran


This is a configuration I am using that works.

I've added the projects from NuGet: EntityFramework (6.0.1) EntityFramework.SqlServerCompact (6.0.1) Microsoft Sql Server Compact Edition (4.0.8876.1). Note, I do not have this assembly flagged to copy local.

I've added the files from the SQLCE 4 private install folders

And then I set my config as follows:

<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
      <section name="SecureSend.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <runtime>
    <loadFromRemoteSources enabled="true" />
    <ThrowUnobservedTaskExceptions enabled="true" />
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="bin"/>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" />
        <bindingRedirect oldVersion="0.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <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>
  <connectionStrings>
    <add name="LocalUserContext" connectionString="Data Source=c:\temp\LocalUserDataStore.sdf" providerName="System.Data.SqlServerCe.4.0" />
  </connectionStrings>
  <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>
like image 31
GeekMarine72 Avatar answered Oct 22 '22 07:10

GeekMarine72