Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 277
MigLuev Avatar asked Nov 21 '13 02:11

MigLuev


People also ask

Which one of the following data provider is not included in ADO.NET framework?

NET Framework Data Provider for OLE DB. This includes the Microsoft OLE DB provider for Exchange and the Microsoft OLE DB provider for Internet Publishing. The . NET Framework Data Provider for OLE DB does not work with the OLE DB provider for ODBC (MSDASQL).

What is Entity client data provider?

The EntityClient provider is a data provider used by Entity Framework applications to access data described in a conceptual model. For information about conceptual models, see Modeling and Mapping. EntityClient uses other . NET Framework data providers to access the data source.

What is Microsoft data SqlClient sni?

dotnet/SqlClient. Microsoft. Data. SqlClient provides database connectivity to SQL Server for . NET applications.

Which is better ADO.NET or Entity Framework Core?

The performance of ADO.Net is better than entity framework because ADO.Net is directly connected to the data source due to that it gives better performance than entity framework, whereas the performance of entity framework is less as compared to the ADO.Net as entity translate the LINQ queries to SQL first and then ...


2 Answers

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>
like image 184
Kirill Bestemyanov Avatar answered Oct 08 '22 05:10

Kirill Bestemyanov


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.

like image 22
MigLuev Avatar answered Oct 08 '22 06:10

MigLuev