89

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?

4 Answers 4

192

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

providerName="System.Data.SqlClient"

3
  • 19
    If using Entity Framework: providerName="System.Data.EntityClient"
    – Dr1Ku
    Commented Oct 23, 2013 at 9:44
  • 3
    I was trying to add this to the connection string. Rather it is a new attribute to the <add /> element. A sibling attribute to the connectionString attribute.
    – Sean B
    Commented May 19, 2015 at 16:27
  • @IronMan84 i got type cast error after using SqlClient and EntityClient worked Commented Mar 5, 2016 at 5:13
16

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"/>
0
2

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>

1
  • +1 for mentioning this is in the web.config, as someone using a product with dozens of different config files
    – apoteet
    Commented Dec 30, 2020 at 17:28
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.