7

我试图在安装了 iis 的 Windows 7 的全新安装上部署一个基本的 MVC 4 应用程序,该应用程序使用 Entity Framework 6(代码优先)和 SQL Compact 4.0(未安装 mvc 4 和 sql compact 4.0)。

我在 db 项目上安装了以下 nuget 包:

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

在 web.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 文件夹(sql ce 文件在 amd64 和 x86 文件夹中:

  • [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
  • 实体框架.dll
  • EntityFramework.SqlServer.dll
  • EntityFramework.SqlServer.xml
  • EntityFramework.SqlServerCompact.dll
  • EntityFramework.SqlServerCompact.xml
  • 实体框架.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

当我部署到干净的机器时,我收到以下错误消息:

找不到请求的 .Net Framework 数据提供程序。它可能没有安装。

在我的开发机器上它工作正常。(我安装了 sql ce)

任何线索我做错了什么?

4

2 回答 2

5

我认为您真正想要做的是管理 NuGet 包,以便为 EntityFramework 添加 SqlServerCompact 支持。只需右键单击您的引用和管理 NuGet 包。然后在对话框中搜索 SqlServerCompact。你应该看到这个:

在此处输入图像描述

添加这个应该添加上面答案中的等效字符串。我最终在 web.config (或 app.config 如果你正在做一个应用程序)

    <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>

抱歉,我迟到了大约一年,但希望这对其他人有所帮助。

于 2014-02-26T01:08:25.220 回答
1

这是我正在使用的有效配置。

我从 NuGet 添加了项目:EntityFramework (6.0.1) EntityFramework.SqlServerCompact (6.0.1) Microsoft Sql Server Compact Edition (4.0.8876.1)。请注意,我没有将此程序集标记为复制本地。

我已经从 SQLCE 4 私有安装文件夹中添加了文件

然后我将我的配置设置如下:

<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>
于 2013-11-06T01:48:45.807 回答