Click here to Skip to main content
15,884,425 members
Articles / Web Development / ASP.NET
Tip/Trick

How to fix Column 'InvariantName' is constrained to be unique

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
25 Mar 2013CPOL1 min read 39.3K   4   5
The build of Web.Debug.Config throws the error as value 'MySql.Data.MySqlClient' is already present.

Introduction 

When you build a web project that uses Enterprise Library Community for the Application Data Block and the MySQL .NET / Connector, VisualStudio throws the error  "Column 'InvariantName' is constrained to be unique. Value 'MySql.Data.MySqlClient' is already present", but you added it only once. 

Is very simple to fix, you need to add "<remove invariant="MySql.Data.MySqlClient"></remove>" to the start of system.data > DbProviderFactories node. 

 Background

You can be confused if you used XML transform for Web.Config, Web.Debug.Config or Web.Release.Config.

But you shouldn't focus in that. The problem is the provider's installation put in machine.config the childNode <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" and normally you put the same manually in your web.config file. So at the compiling time, when web.config heritates maching.config, it results in duplicate "add" child with the same invariant attribute, with the value "MySql.Data.MySqlClient" .

The examples of use around Internet and the tutorials of ELContrib Application Data Block add the DbProviderFactories node to System.Data element. It suposes that the MySQL .NET/Connector aren't installed in system. It suposes the mysql.data.dll is referenced in any directory and the configuration isn't heritated from machine.config

Using the code 

Your XML block must be like this to solve the problem: 

C++
<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.2.4.0, Culture=neutral" />
  </DbProviderFactories>
</system.data>

Remember to add <remove invariant="MySql.Data.MySqlClient"></remove> at the start of DbProviderFactories.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead Get Me An Apartment
Spain Spain
I'm developer fall in love with C#, .NET and Mono.
Designing and programming websites since 2001.
I like literature (to read and to write), playing football (soccer)... and of course I'm great fan of La Roja (Spain football team)

At now I work in GetMeAnApartment, I do Research and Development features to upgrade our website (asp.net, MVC, MySQL) and business model (rental short stay apartments)


My Knowledge:
LANGUAGES: C#, XML, HTML, JavaScript, ActionScript, php, VisualBasic Script

TECHNOLOGIES: asp.net, asp.net mvc, php, flash, GTK#

APPLICATIONS: wordpress, wikimedia, I programmed modules for Macromedia Flash MX for myself

FRAMEWORKS: .Net Framework, Mono

SERVERS: IIS, apache2

SO: Windows, Debian

SOFTWARE: Visual Studio 2010, 2008. Monodevelop. Glade. Illustrator. Indesign. Photoshop. Dreamweaver.


Employment:

GetMeAnApartment
IT Director and website developer, 2010 - present

Círculo Rojo Publicidad y Comunicación
IT Director and websites developer, 2007 - 2010

Dédalo Creative
Co-founder,Programmer and Developer, Graphical designer 2006 - 2007

Costa Mediterránea Comunicación
Chief writer, 2004 - 2006

Stalker Creacion
Web designer and developer, 2001 - 2003

Education
Myself
Designer and Programmer, 2001 - present

Jaime I, University
Advertising, 2000 - 2005

Comments and Discussions

 
QuestionUnfortunately didn't resolve Pin
Wade Murdock7-Feb-24 0:19
Wade Murdock7-Feb-24 0:19 
QuestionThank you very much Pin
Manuel Rodriguez Sep202312-Sep-23 7:58
Manuel Rodriguez Sep202312-Sep-23 7:58 
Questionmuchas gracias Excelente !! Pin
Manuel Rodriguez Sep202312-Sep-23 8:35
Manuel Rodriguez Sep202312-Sep-23 8:35 
Questionfacing another error Pin
มด ย่อง17-Sep-13 17:30
มด ย่อง17-Sep-13 17:30 
AnswerRe: facing another error Pin
AlbertoLeon CSharpMan17-Sep-13 22:46
AlbertoLeon CSharpMan17-Sep-13 22:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.