No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'.

.net asp.net c# entity-framework-6 sql-server

Question

EntityFramework 6 is what we're using with Code First. A console app that we have reads the connection string from its App.config but does not mention EntityFramework. It uses the connection string as an argument when calling the DatabaseInitializationUtilities assembly.

The reference to EF6 is found in DatabaseInitializationUtilities (EntityFramework and EntityFramework.SqlServer). This is its App.config:

<?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>
     <system.serviceModel>
         <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_IAuthentication" />
            </basicHttpBinding>
         </bindings>
         <client>
            <endpoint address="http://localhost/SecurityServices/Authentication.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAuthentication" contract="SecurityService.IAuthentication" name="BasicHttpBinding_IAuthentication" />
         </client>
      </system.serviceModel>
      <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>
   </configuration>

when the line where DatabaseInitializationUtilities tries to launch a script is reached in the execution

context.Database.ExecuteSqlCommand(script.ScriptText)

When a mistake occurs,

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.

I think the solution is exactly what I have in my configuration file, therefore I don't know what the issue is.

The element 'EntityFramework' has an invalid child element 'providers,' according to Resharper, who is bluelining the node. However, when I installed EF6, NuGet injected the section.

Any thoughts?

1
36
1/17/2014 12:32:29 AM

Popular Answer

You must make a reference for it in order for it to be copied into the debug folder. It can then be accessible during runtime.

Don't copy any files; simply make a note of this:

private volatile Type _dependency;

public MyClass()
{
    _dependency = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
}
52
10/21/2016 1:45:09 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow