The connection string 'MyConnection' in the application's configuration file does not contain the required providerName attribute."

Entity FrameworkEf Code-FirstConnection String

Entity Framework Problem Overview


I use Entity Framework Code First,

My connection string is in a configuration file:

<connectionStrings>
    <clear/>
    <add name="ApplicationServices" connectionString="Data Source=PC-X;Initial Catalog=MYdb;Integrated Security=True"/>
  </connectionStrings>

When I try to access the data (something that should create the DB) is falling with the following error:

> The connection string 'ApplicationServices' in the application's > configuration file does not contain the required providerName > attribute."

What am I missing?

Entity Framework Solutions


Solution 1 - Entity Framework

You're missing the following piece of code after the connectionString attribute (assuming that you're using SQL):

providerName="System.Data.SqlClient"

Solution 2 - Entity Framework

Sometime in the future. the complete code

<add name="YouContext" connectionString="Integrated Security=True;Persist Security Info=False;Initial Catalog=YourDatabaseName;Data Source=YourPCName;" providerName="System.Data.SqlClient"/>

Solution 3 - Entity Framework

Go down in your web.config until you reach the providers tag. For instance, here's my providers statement:

<providers><provider invariantName="System.Data.SqlClient" ... /></providers>

you should add this System.Data.SqlClient as a provider name in your connection string so your connection string should look like this:

  <connectionStrings>
 <add name="ApplicationServices" providerName="System.Data.SqlClient" connectionString="Data Source=PC-X;Initial Catalog=MYdb;Integrated Security=True"/>
  </connectionStrings>

Solution 4 - Entity Framework

In my case the problem was with an incorrect StartUp project target. In the PM console the target migration assembly project was correct.

I have a multiproject solution and the target was on some web-service project.

So I changed the StartUp to the main WebSite project and the migration have complited without errors.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHodaya ShalomView Question on Stackoverflow
Solution 1 - Entity FrameworkCorey AdlerView Answer on Stackoverflow
Solution 2 - Entity FrameworkKrishneilView Answer on Stackoverflow
Solution 3 - Entity FrameworkAhmad HamedView Answer on Stackoverflow
Solution 4 - Entity FrameworkKamertonView Answer on Stackoverflow