1
votes

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.

3

3 Answers

4
votes

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.

1
votes

I also had a similar problem

My problem was solved by doing the following:

enter image description here

enter image description here

0
votes

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"