1

Hello guys I am strugling with connecting to sql database server. I am using Entity framework v6 and trying code first approach for the first time. Below I will show you my app.config file and error message I get I checked out similar questions and most of answers were about missing EntityFramework.SqlServer.dll I have this dll referenced

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <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>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="HotelDB"
         connectionString="Data Source=(localdb)\v11.0;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"/>
  </connectionStrings>
</configuration>

Error Message:

System.InvalidOperationException: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Thomas Ayoub
  • 27,208
  • 15
  • 85
  • 130
Dargor66
  • 33
  • 2
  • 8

3 Answers3

4

Have you found a solution for this problem? Otherwise you could take a look here: Entity Framework Provider type could not be loaded?

Most of the time when I see this exception it's because the web application doesn't have Entity Framework installed (and / or missing the EntityFramework.SqlServer.dll).

So to give an example, if you have 2 projects in a solution:

  • WebApp
  • DataAccess

and with Entity Framework installed in the DataAccess project. When wanting to call a method on a class (for example a repository) from the DataAccess project within the WebApp, 2 things are needed:

  • WebApp needs a reference to DataAccess
  • Webapp also needs EF to be installed

When DataAccess has EF installed and then added as a reference to WebApp, the WebApp project will (normally) also install EF. Sometimes in unexpected situations the installation of EF in the WebApp fails. Therefore not adding the needed references and showing the exception message you mentioned. Hopefully this answer will help some others.

Melisco
  • 413
  • 4
  • 17
  • 1
    But I thought the point of the data access layer was to avoid that? The data access layer is like its own entity. And all you have to do is make a reference to that project from any other project, and they can all use those methods without having entity framework installed? The reason I say this is because, what happens if you say have 15 projects referencing that. If you need to update entity framework, you do it 15 times then re-dploy all projects? I find that hard to believe its the best way. – MZawg Dec 12 '18 at 17:07
1

I also had a similar problem

My problem was solved by doing the following:

enter image description here

enter image description here

BehrouzMoslem
  • 6,792
  • 3
  • 24
  • 33
  • 1
    Please don't post identical answers to multiple questions. Post one good answer, then vote/flag to close the other questions as duplicates. If the question is not a duplicate, *tailor your answers to the question.* – Paul Roub Oct 12 '17 at 15:12
0

If nothing of the solutions worked then check both the packages.config of WebApp and DataAccess for the version of Entity Framework. In case you see or don't see the entry of EF in the packages.config file of WebApp, go to the reference and delete the EF from WebApp and install it again using the package manager console giving the following command:

Install-Package "EntityFramework" -Version (Version number) where Version number is the version that's present in the packages.config of DataAccess. Example: Install-Package "EntityFramework" -Version "6.1.3"