19

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', the error has the following message:

"The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details."

As the answers to the related question suggest, I have reinstalled Entity Framework (EF6) via the Package Manager Console, but the error persists. I also checked that EntityFramework.SqlServer.dll is referenced in my project. Here is the connection string as stored in App.config:

<add name="DesignModel"    ConnectionString="metadata=res://*/DesignModel.csdl|res://*/DesignModel.ssdl|res://*/DesignModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=C071E;initial catalog=CTD2;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />     

I have another project where I used EntityFramework to create the exact same entities and context, and it works fine, which makes this all more puzzling.

The error is shown when trying to execute this lines:

DesignModel designContext = new DesignModel();
designContext.MoPerfIDs.Load();

where DesignModel is the name of the class that inherits DbContext.

Here's the full App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
       <section name="ppe.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
    <!-- 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>

  <connectionStrings>
    <add name="DesignModel" connectionString="metadata=res://*/DesignModel.csdl|res://*/DesignModel.ssdl|res://*/Design    Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MONNMC071E;initial catalog=CTD2;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
        <parameters>
            <parameter value="System.Data.SqlClient" />
        </parameters>
    </defaultConnectionFactory>
    <providers>
        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
</entityFramework>
</configuration>

Any help will be appreciated. Thanks in advance.

Community
  • 1
  • 1
MigLuev
  • 201
  • 1
  • 2
  • 6
  • And what are the inner exceptions? – Pawel Nov 21 '13 at 21:18
  • 1
    Is the EntityFramework.SqlServer.dll in the bin? – Jace Rhea Feb 25 '14 at 22:26
  • 3
    I'm having the same exact problem. I can't simply create another solution to fix this. I also don't understand how this is closed as 'off-topic'. – Mike Becatti Jul 28 '14 at 15:58
  • It does not seems to me as off topic question. This question has 15 thousand views! I am facing the same problem and I cannot solved it. It seems to me that it is problem of MySQL and EntityFramework which can be somehow bypassed. The provided answer didn't help to me. I hope the question will be reopened we can together find a solution. – Tomas Kubes Dec 18 '15 at 15:07
  • @Pawel: I would like to check the inner exception, but I don't know how. The message appaers after pressing build (F6) in error window. – Tomas Kubes Dec 18 '15 at 15:09

9 Answers9

3

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>
Kirill Bestemyanov
  • 11,946
  • 2
  • 24
  • 38
  • OP isn't using `LocalDb` check the EF connection string. – Aron Nov 21 '13 at 03:09
  • Thanks both for the responses. I tried as suggested, however I'm still getting the same error. I edited the question and posted the full App.config file. Very confusing as in the other project where the error doesn't appear the only thing in App.config is the connection string for entity framework. – MigLuev Nov 21 '13 at 15:57
  • @MigLuev: It does not help for me either. Did you managed to solved it finally? – Tomas Kubes Dec 18 '15 at 15:19
1

Still not sure what was causing the problem, but ended up creating a new solution and copying everything from my project. Now works fine. Really weird, indeed.

MigLuev
  • 201
  • 1
  • 2
  • 6
1

Simply install "MySql.Data.Entity" from nuget! It will install mysql ado driver and entity driver automatically!

Linojan
  • 136
  • 1
  • 4
  • 10
0

Wow...that is pretty special...Anyways. You need to register the Entity Framework provider for the System.Data.SqlClient SQL connection type.

You want to add the following to your app.config/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" />
  </configSections>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlClient" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
</configuration>
Aron
  • 15,464
  • 3
  • 31
  • 64
0

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.

Louis Nguyen
  • 139
  • 1
  • 1
  • 3
0

Try adding

var _ = System.Data.Entity.SqlServer.SqlProviderServices.Instance;

in the ctor of your designContext.

ND72
  • 2,037
  • 1
  • 15
  • 14
0

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.

Blue Clouds
  • 7,295
  • 4
  • 71
  • 112
0

I got this error but for me it was something entirely different.

I had to edit:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config

And:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config

Searching for DbProviderFactories both configs looked like this:

<system.data>
    <DbProviderFactories>
        <add name="IBM DB2 for i .NET Provider" invariant="IBM.Data.DB2.iSeries" description=".NET Framework Data Provider for IBM i" type="IBM.Data.DB2.iSeries.iDB2Factory, IBM.Data.DB2.iSeries, Version=12.0.0.0, Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26" />
    </DbProviderFactories>
    <DbProviderFactories />
</system.data>

When I removed the trailing <DbProviderFactories /> everything started working again.

I was able to solve it by looking at only Unable to find the requested .Net Framework Data Provider and finding this answer:

https://stackoverflow.com/a/9929534/3850405

Ogglas
  • 62,132
  • 37
  • 328
  • 418
-1

If you get this error on Visual Studio while debugging, this happens after you installed another DB provider or IDE with DB Provider. I faced this error after I installed Delphi on my computer.

Solution: Just edit C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config and remove tags.

H. Aydin
  • 340
  • 3
  • 10