Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 778
Hodaya Shalom Avatar asked Feb 25 '13 14:02

Hodaya Shalom


3 Answers

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

providerName="System.Data.SqlClient"

like image 107
Corey Adler Avatar answered Oct 14 '22 17:10

Corey Adler


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"/>
like image 29
Krishneil Avatar answered Oct 14 '22 17:10

Krishneil


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>

like image 24
Ahmad Hamed Avatar answered Oct 14 '22 19:10

Ahmad Hamed