不变名称System.Data.SqlClient的提供程序被多次指定 [英] The provider for invariant name System.Data.SqlClient is specified multiple times

查看:132
本文介绍了不变名称System.Data.SqlClient的提供程序被多次指定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将Entity Framework更新到6.0,现在我收到一个例外,我无法弄清楚。


创建entityFramework的配置部分处理程序时出错:在应用程序配置中多次指定不变名称System.Data.SqlClient的提供程序。每个已配置的提供程序的不变名称必须是唯一的。 (C:\inetpub\wwwroot\scrape\Scrape\web.config第106行)



System.Data.Entity.Internal的类型初始化程序.AppConfig'抛出一个异常。


web.config没有多次列出提供商,只有一个网页。配置为整个项目。我很感谢任何帮助。



堆栈跟踪

$ b $在System.Data.Entity.Internal.LazyInternalConnection..ctor(String nameOrConnectionString)的System.Data.Entity.Internal.AppConfig.get_DefaultInstance()



中的b



在System.Data.Entity.DbContext..ctor(String nameOrConnectionString)



在Scrape.Data。 C:\inetpub\wwwroot\scrape\Scrape.Data\Contexts\ScabsContext.cs中的Contexts.ScabsContext..ctor()在第17行



在Scrape.Data.Repositories.ScabStore..ctor()在c:\inetpub\wwwroot\scrape\Scrape.Data\Repositories\ScabStore.cs:第15行


在c:\inetpub\wwwroot\scrape\Scrape\Controllers\ScabsController.cs第28行

$的Scrape.Api.Controllers.ScabsController.get_store()中的

b
$ b

在Scrape.Api.Controllers.ScabsController.Post(Scab scab)中的c:\ine tpub\wwwroot\scrape\Scrape\Controllers\ScabsController.cs:第52行



在lambda_method(Closure,Object,Object [])



在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor。<> c_ DisplayClassc.b _6(Object instance,Object [] methodParameters)



在System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance,Object [] arguments)



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


而我的web.config

 < configuration> 
< configSections>
< section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/> ;
<! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468 - >
< / configSections>
< connectionStrings>
< add name =ScabContextproviderName =System.Data.SqlClientconnectionString =Data Source = bfleming-dev; Initial Catalog = scabs; User ID = scabs_dbo; Password = password/>
< add name =lmsReadWriteconnectionString =Initial Catalog = caV2; Data Source = devsqlnow1.ca-schools.org; Network Library = dbmssocn; User Id = webuser; Password = hyqxYVTH9bjW; MultipleActiveResultSets = True; NAME = connexus_main; />
< add name =lmsReadOnlyconnectionString =Initial Catalog = caV2; Data Source = devsqlnow1.ca-schools.org; Network Library = dbmssocn; User Id = webuser; Password = hyqxYVTH9bjW; MultipleActiveResultSets = True; NAME = connexus_main; />
< / connectionStrings>
< appSettings>
< add key =webpages:Versionvalue =3.0.0.0/>
< add key =webpages:Enabledvalue =false/>
< add key =PreserveLoginUrlvalue =true/>
< add key =ClientValidationEnabledvalue =true/>
< add key =UnobtrusiveJavaScriptEnabledvalue =true/>
< / appSettings>
< system.web>
< compilation debug =truetargetFramework =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 =DefaultProfileProvidertype =System.Web.Providers.DefaultProfileProvider,System.Web.Providers,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35connectionStringName =DefaultConnectionapplicationName = //>
< / providers>
< / profile>
< membership defaultProvider =DefaultMembershipProvider>
< providers>
< add name =DefaultMembershipProvidertype =System.Web.Providers.DefaultMembershipProvider,System.Web.Providers,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35connectionStringName =DefaultConnectionenablePasswordRetrieval = falseenablePasswordReset =truerequiresQuestionAndAnswer =falserequiresUniqueEmail =falsemaxInvalidPasswordAttempts =5minRequiredPasswordLength =6minRequiredNonalphanumericCharacters =0passwordAttemptWindow =10applicationName =//>
< / providers>
< / membership>
< roleManager defaultProvider =DefaultRoleProvider>
< providers>
< add name =DefaultRoleProvidertype =System.Web.Providers.DefaultRoleProvider,System.Web.Providers,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35connectionStringName =DefaultConnectionapplicationName = //>
< / providers>
< / roleManager>
<! -
如果要部署到具有多个Web服务器实例的云环境,则
您应该将会话状态模式从InProc更改为自定义。另外,
更改名为DefaultConnection的连接字符串连接到SQL Server(包括SQL Azure和SQL Compact)的实例
而不是SQL Server Express。
- >
< sessionState mode =InProccustomProvider =DefaultSessionProvider>
< providers>
< add name =DefaultSessionProvidertype =System.Web.Providers.DefaultSessionStateProvider,System.Web.Providers,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35connectionStringName =DefaultConnection/> ;
< / providers>
< / sessionState>
< /system.web>
< system.webServer>
< validation validateIntegratedModeConfiguration =false/>
<处理程序>
< remove name =ExtensionlessUrlHandler-Integrated-4.0/>
< remove name =OPTIONSVerbHandler/>
< remove name =TRACEVerbHandler/>
< add name =ExtensionlessUrlHandler-Integrated-4.0path =*。 verb =*type =System.Web.Handlers.TransferRequestHandlerpreCondition =integratedMode,runtimeVersionv4.0/>
< / handlers>
< /system.webServer>
<运行时>
< assemblyBinding xmlns =urn:schemas-microsoft-com:asm.v1>
< dependentAssembly>
< assemblyIdentity name =System.Web.HttppublicKeyToken =31bf3856ad364e35culture =neutral/>
< bindingRedirect oldVersion =0.0.0.0-5.1.0.0newVersion =5.1.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =EntityFrameworkpublicKeyToken =b77a5c561934e089/>
< bindingRedirect oldVersion =0.0.0.0-6.0.0.0newVersion =6.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =WebGreasepublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =0.0.0.0-1.3.0.0newVersion =1.3.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.HelperspublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.WebPagespublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-3.0.0.0newVersion =3.0.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Web.MvcpublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-5.1.0.0newVersion =5.1.0.0/>
< / dependentAssembly>
< dependentAssembly>
< assemblyIdentity name =System.Net.Http.FormattingpublicKeyToken =31bf3856ad364e35/>
< bindingRedirect oldVersion =1.0.0.0-5.1.0.0newVersion =5.1.0.0/>
< / dependentAssembly>
< / assemblyBinding>
< / runtime>
< entityFramework>
< defaultConnectionFactory type =System.Data.Entity.Infrastructure.SqlConnectionFactory,EntityFramework/>
< providers>
< provider invariantName =System.Data.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< / providers>
< / entityFramework>
< / configuration>


解决方案

问题是 / entityFramework / providers 部分对异常中指定的不变量有一个重复的提供者。

 < provider invariantName =System.Data.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/> 

即使你只指定一个,可能发生的是在.config中指定一个文件在父目录中。由于.config文件从父级继承配置,所以看到它被定义了两次。



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



根据 CodePlex项目,这是6.1.0-alpha1中的修复忽略确切的重复。


I've update Entity Framework to 6.0 and now I'm getting an exception that I can't figure out.

An error occurred creating the configuration section handler for entityFramework: The provider for invariant name 'System.Data.SqlClient' is specified multiple times in the application configuration. The invariant name must be unique for each configured provider. (C:\inetpub\wwwroot\scrape\Scrape\web.config line 106)

The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.

The web.config doesn't have the provider listed multiple times and I only have one web.config for the whole project. I'm grateful for any help.

Stack Trace

at System.Data.Entity.Internal.AppConfig.get_DefaultInstance()

at System.Data.Entity.Internal.LazyInternalConnection..ctor(String nameOrConnectionString)

at System.Data.Entity.DbContext..ctor(String nameOrConnectionString)

at Scrape.Data.Contexts.ScabsContext..ctor() in c:\inetpub\wwwroot\scrape\Scrape.Data\Contexts\ScabsContext.cs:line 17

at Scrape.Data.Repositories.ScabStore..ctor() in c:\inetpub\wwwroot\scrape\Scrape.Data\Repositories\ScabStore.cs:line 15

at Scrape.Api.Controllers.ScabsController.get_store() in c:\inetpub\wwwroot\scrape\Scrape\Controllers\ScabsController.cs:line 28

at Scrape.Api.Controllers.ScabsController.Post(Scab scab) in c:\inetpub\wwwroot\scrape\Scrape\Controllers\ScabsController.cs:line 52

at lambda_method(Closure , Object , Object[] )

at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c_DisplayClassc.b_6(Object instance, Object[] methodParameters)

at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)

at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)

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

解决方案

The problem is the configuration/entityFramework/providers section has a duplicate provider for the invariant specified in the exception.

<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />

Even though you only specified one, what is likely happening is that there is one specified in a .config file in a parent directory. Since .config files inherit configuration from parents, it's seeing that it's being defined twice.

You can probably remove this provider safely for this application.

Based on the CodePlex project, this has been "fixed" in 6.1.0-alpha1 by ignoring exact duplicates.

这篇关于不变名称System.Data.SqlClient的提供程序被多次指定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆