Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 多次指定了不变名称System.Data.SqlClient的提供程序_C#_Entity Framework_Exception - Fatal编程技术网

C# 多次指定了不变名称System.Data.SqlClient的提供程序

C# 多次指定了不变名称System.Data.SqlClient的提供程序,c#,entity-framework,exception,C#,Entity Framework,Exception,我已经将Entity Framework更新为6.0,现在我遇到了一个无法解决的异常 创建entityFramework的配置节处理程序时出错:在应用程序配置中多次指定了固定名称“System.Data.SqlClient”的提供程序。对于每个配置的提供程序,固定名称必须是唯一的。(C:\inetpub\wwwroot\scrape\scrape\web.config第106行) “System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发异常 web.c

我已经将Entity Framework更新为6.0,现在我遇到了一个无法解决的异常

创建entityFramework的配置节处理程序时出错:在应用程序配置中多次指定了固定名称“System.Data.SqlClient”的提供程序。对于每个配置的提供程序,固定名称必须是唯一的。(C:\inetpub\wwwroot\scrape\scrape\web.config第106行)

“System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发异常

web.config没有多次列出提供程序,我只有一个web.config用于整个项目。我很感激你的帮助

堆栈跟踪

在System.Data.Entity.Internal.AppConfig.get_DefaultInstance()中

位于System.Data.Entity.Internal.LazyInternalConnection..ctor(字符串名称或连接字符串)

位于System.Data.Entity.DbContext..ctor(字符串名称或连接字符串)

在c:\inetpub\wwwroot\Scrape\Scrape.Data\Contexts\ScabsContext.cs中的Scrape.Data.Contexts.ScabsContext..ctor()处:第17行

在c:\inetpub\wwwroot\scrap\scrap.Data\Repositories\ScabStore.cs中的scrap.Data.Repositories.ScabStore..ctor()处:第15行

在c:\inetpub\wwwroot\Scrape\Scrape\Controllers\ScabsController.cs中的Scrape.Api.Controllers.ScabsController.get\u store()处:第28行

在c:\inetpub\wwwroot\Scrape\Scrape\Controllers\ScabsController.cs中的Scrape.Api.Controllers.ScabsController.Post(Scab-Scab)处:第52行

在lambda_方法(闭包、对象、对象[])

在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.c_DisplayClassc.b_6(对象实例,对象[]方法参数)

位于System.Web.Http.Controller.ReflectedHttpActionDescriptor.ActionExecutor.Execute(对象实例,对象[]参数)

位于System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,IDictionary`2参数,CancellationToken CancellationToken)

和我的web.config

<configuration>
  <configSections>
    <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>
  <connectionStrings>
    <add name="ScabContext" providerName="System.Data.SqlClient" connectionString="Data Source=bfleming-dev;Initial Catalog=scabs;User ID=scabs_dbo;Password=password" />
    <add name="lmsReadWrite" connectionString="Initial Catalog=caV2;Data Source=devsqlnow1.ca-schools.org;Network Library=dbmssocn;User Id=webuser;Password=hyqxYVTH9bjW;MultipleActiveResultSets=True;Application Name=connexus_main;" />
    <add name="lmsReadOnly" connectionString="Initial Catalog=caV2;Data Source=devsqlnow1.ca-schools.org;Network Library=dbmssocn;User Id=webuser;Password=hyqxYVTH9bjW;MultipleActiveResultSets=True;Application Name=connexus_main;" />
  </connectionStrings>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="None" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <profile defaultProvider="DefaultProfileProvider">
      <providers>
        <add name="DefaultProfileProvider" type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </profile>
    <membership defaultProvider="DefaultMembershipProvider">
      <providers>
        <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
      </providers>
    </membership>
    <roleManager defaultProvider="DefaultRoleProvider">
      <providers>
        <add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" applicationName="/" />
      </providers>
    </roleManager>
    <!--
            If you are deploying to a cloud environment that has multiple web server instances,
            you should change session state mode from "InProc" to "Custom". In addition,
            change the connection string named "DefaultConnection" to connect to an instance
            of SQL Server (including SQL Azure and SQL  Compact) instead of to SQL Server Express.
      -->
    <sessionState mode="InProc" customProvider="DefaultSessionProvider">
      <providers>
        <add name="DefaultSessionProvider" type="System.Web.Providers.DefaultSessionStateProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" />
      </providers>
    </sessionState>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.1.0.0" newVersion="5.1.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>


尝试注释提供者部分,保存并重新运行。它可能与此相关

问题在于
配置/entityFramework/providers
部分对异常中指定的不变量具有重复的提供程序


尽管您只指定了一个,但可能发生的情况是在父目录的.config文件中指定了一个。由于.config文件从父级继承了配置,因此它被定义了两次

您可能可以为此应用程序安全地删除此提供程序


基于,这在6.1.0-alpha1中已通过忽略完全相同的副本“修复”。

我收到此错误,因为“EntityFramework.SqlServer.dll”文件未包含在此项目的发布中。
将此DLL添加到web服务器bin文件夹修复了此问题。

要修复此问题,我将父文件夹web.config
entityFramework
部分包装为: