Click here to Skip to main content
Click here to Skip to main content
Go to top

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

, 25 Mar 2013
Rate this:
Please Sign up or sign in to vote.
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: 

  <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)

Share

About the Author

AlbertoLeon CSharpMan
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
Follow on   Twitter

Comments and Discussions

 
Questionfacing another error Pinmemberมด ย่อง17-Sep-13 17:30 
AnswerRe: facing another error PinmemberAlbertoLeon CSharpMan17-Sep-13 22:46 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 25 Mar 2013
Article Copyright 2013 by AlbertoLeon CSharpMan
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid