6

I am trying to use MySQL database in MVCMusicStore
http://mvcmusicstore.codeplex.com/ instead of MSSQL.
I would like to learn Code first development with MySQL.
I had added these code to web.config

<connectionStrings>
  <add name="MusicStoreEntities"
       connectionString="Server=localhost; Database=MvcMusicStore; Uid=root; Pwd=;"
       providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
<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.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  </DbProviderFactories>   
</system.data>

MySQL database is already created but tables are not created. I have just added Mysql.Data.MySQLClient.dll reference to my project. And I have this kind of exception:

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.
(C:\Users\Dauren\Downloads\MvcMusicStore-v3.0\MvcMusicStore-v3.0\MvcMusicStore-Completed\MvcMusicStore\web.config line 47)

Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
Dauren
  • 145
  • 1
  • 7
  • 1
    Thank you for the question and answer. Another question on the topic: http://stackoverflow.com/questions/7354116/net-mysql-connector-conflicting-dbproviderfactories – ses011 Oct 17 '12 at 22:24

1 Answers1

13

Try this code:

 <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.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />  
  </DbProviderFactories>
Devart
  • 119,203
  • 23
  • 166
  • 186
  • Now i have this kind of error: _Model compatibility cannot be checked because the database does not contain model metadata. Ensure that IncludeMetadataConvention has been added to the DbModelBuilder conventions._ – Dauren May 04 '11 at 10:39
  • 1
    @Dauren, you should either add (or simply don't remove) the IncludeMetadataConvention, or use some other database initialization strategy (not DropCreateDatabaseIfModelChanges). – Devart May 10 '11 at 12:25
  • Thanks, Above worked for me. Just a note, I was using different version of MySql.Data assembly, so just changed the Version 6.3.6.0 to Version=6.4.4.0. – Himalaya Garg Nov 04 '16 at 07:57