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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…