Entity Framework ADO.NET Sql.Data.Client provider not found

后端 未结 9 2224
天涯浪人
天涯浪人 2020-12-10 11:36

I have a similar problem as the one presented in the question No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'

相关标签:
9条回答
  • 2020-12-10 12:31

    You need to register the Entity Framework provider for the System.Data.SqlClient SQL connection type. you should have in app.config:

    <configSections>
        <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
        <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </configSections>
      <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
          <parameters>
            <parameter value="v11.0" />
          </parameters>
        </defaultConnectionFactory>
        <providers>
          <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
        </providers>
      </entityFramework>
    
    0 讨论(0)
  • 2020-12-10 12:35

    The problem in my case was that inorder to catch another exception I had enabled CLR exceptions. And I forgot to disable it.

    I disabled it in my exception setting. and it overlooked this exception and went on to run and create a db for me (in my case) automatically.

    0 讨论(0)
  • 2020-12-10 12:36

    There are 2 options which you can try.

    1) Load "System.Data.SqlClient" manually

    Include the follow statement in your context class

    var type = typeof(System.Data.Entity.SqlServer.SqlProviderServices);

    2) Don't load "System.Data.SqlClient"

    By change from

    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
    

    to

    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
    

    I hope your issue is resolved.

    0 讨论(0)
提交回复
热议问题