2

I am using Entity Framework 6 in my APS.NET 4.5 web application.

When running the following command:

using (var db = new booksEnteties())
{
    var books = from b in db.books
    select b;
} 

I get the following error:

An exception of type 'System.Configuration.ConfigurationErrorsException' occurred in System.Configuration.dll but was not handled in user code

In the Details:

Unrecognized attribute 'name'.

And it pointing me to the web.config line 111:

 <remove name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" />

When I removed this line and try to run again, I get the following error:

An error occurred creating the configuration section handler for system.data: Column 'InvariantName' is constrained to be unique. Value 'MySql.Data.MySqlClient' is already present.

I assume that is something related to the Entity Framework 6 configuration in the web.config.

Humayun Shabbir
  • 2,961
  • 4
  • 20
  • 33
Liron Harel
  • 10,819
  • 26
  • 118
  • 217
  • Can you post your .config? At the very least all of the XML (with structure) that contains connection/db info. Just noticed the line #111. Just the specific stuff would be good. – TyCobb Jul 31 '14 at 18:47

3 Answers3

4

As Tim Tang has stated, if you are using Entity Framework 6 for you need to use Connector/NET 6.8.x. You should also add a reference to the MySql.Data.Entity.EF6 to you project.

enter image description here

Then for your Web.config file, something like this:

 <entityFramework>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" 
                type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient"></remove>
      <add name="MySQL Data Provider" 
           invariant="MySql.Data.MySqlClient" 
           description=".Net Framework Data Provider for MySQL" 
           type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,  Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
  </system.data>

Look at this for more details.

Kinyanjui Kamau
  • 1,890
  • 10
  • 55
  • 95
2

Just adding a summary of versions

  • For EF4, use Connector/NET 6.6.x (current GA is 6.6.6)
  • For EF5, use Connector/NET 6.7.x (current GA is 6.7.4) or Connector/NET 6.8.x (current GA is 6.8.3).
  • For EF6, use Connector/NET 6.8.x (current GA is 6.8.3).

in EF5 or less, all ok. in EF6, you need to use mysql connector 6.8.x, and add DbConfigurationTypeAttribute to you DbContext:

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class DemoContext : DbContext{}

which MySqlEFConfiguration is in MySql.Data.Entity.EF6.dll in 6.8.x. Have a try!

Tim.Tang
  • 3,158
  • 1
  • 15
  • 18
  • also try this link: http://stackoverflow.com/questions/7354116/net-mysql-connector-conflicting-dbproviderfactories – Tim.Tang Aug 01 '14 at 02:17
1

The error is very specific... Its complaining about the attribute 'Name' Your problem is on this line:

<remove name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" />

Name is invalid here, just remove it so it should be like this:

<remove invariant="MySql.Data.MySqlClient" />
Talon
  • 3,466
  • 3
  • 32
  • 47