Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm using the .NET MySQL Connector with Entity Framework 4, and everything worked great but I wanted to package the MySQL client DLL files with my application when deployed on servers so we don't have to worry about installing mysql on each server, each application will just have the correct copy that it needs.

To make this possible, I made sure the MySQL references had "Copy Local" set so they would be copied to the bin folders and added the following to my app.config:

<system.data>
    <DbProviderFactories>
      <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.3.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
</system.data>

This works and I am able to deploy the app without installing mysql on the remote server, but now I have a problem on my local dev machine(where I do have the MySQL connector installed), and I'm getting this error when EF tries to connect:

Column 'InvariantName' is constrained to be unique. Value 'MySql.Data.MySqlClient' is already present.

If I comment out the XML I added above in the app.config, the error goes away. This is likely because the same driver is installed on the system and is in the machine.config.

What is the solution? I would rather not have to manually comment and uncomment the line depending on which system I build the application for.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
236 views
Welcome To Ask or Share your Answers For Others

1 Answer

try to add < remove invariant="MySql.Data.MySqlClient" / > in your webconfig. On your computer, you have installed the Connector for MySql and your machine.config have been modified by adding an item in the DbProviderFactories. So if you put another MySql Data Provider in your web.config, its like if you are trying to register the same thing twice.

<system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <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.3.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
</system.data>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...