Unable to Retrieve Metadata Unable to Retrieve Metadata mysql mysql

Unable to Retrieve Metadata


It seems that MVC4 Controller scaffolding is not properly recognizing MySql Connection String. Change the connection string as shown below when generating EF CRUD code for Controllers:

<connectionStrings>    <add name="BTDContext" connectionString="Data Source=host_name;Database=database_name;uid=user_id;pwd=password;" providerName="System.Data.SqlClient" /> </connectionStrings>

Change it back to standard when running the application:

<connectionStrings>    <add name="BTDContext" connectionString="Data Source=host_name;Database=database_name;uid=user_id;pwd=password;" providerName="MySql.Data.MySqlClient" /> </connectionStrings>

Note the change, provider name.


The imesh suggesting almost solve my problem, but additionally I temporary commented line

[DbConfigurationType(typeof(MySqlEFConfiguration))]

which was in DBContext class. And of course after creation controller this line should be uncommented and change back System.Data.SqlClient to MySql.Data.MySqlClient in config file.


Using VS 2013, MySQL Connector/NET 6.9.6, Entity Framework 6, Web API 2.2 and MySQL server 5.7 I had to combine the answers to prevent the error about "Unable to retrieve metadata".

To successfully add a controller to a .NET project that uses a MySQL connection, do the following:

  1. Temporarily add a connection string with System.Data.SqlClient as the providerName, and comment the one for MySQL. It doesn't matter whether the connection string is valid.
  2. Ensure that MySqlEFConfiguration isn't enabled in any way.
  3. Rebuild.

About the second point, the MySQL documentation on using Connector/NET with EF6 states three possible ways to enable the MySqlEFConfiguration. Ensure that none of these are enabled while adding controllers using the VS template.

  1. Adding the DbConfigurationTypeAttribute on the context class:

[DbConfigurationType(typeof(MySqlEFConfiguration))]

  1. Calling DbConfiguration.SetConfiguration(new MySqlEFConfiguration()) at the application startup

  2. Set the DbConfiguration type in the configuration file:

<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">