1

I am new to asp.net, and I am now facing a problem.

I have created a project using asp.net mvc4, and I have added an entity data model and successfully connected to MySQL. but when I tried to create a controller, I got the error message stated as below:

"unable to retrieve metadata for "client_test.client", Unable to find the requested .NET Framework data provider. it may not be installed."

from the "scaffolding options", I choose the template:

"MVC controller with read/write actions and views using Entity Framework"

and from the machine.config file, I could see MySQL data provider is there.

<DbProviderFactories>
  <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
  <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.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>

and the connectionString in the web.config is like this:

<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-client_test-20130916144039;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-client_test-20130916144039.mdf" providerName="System.Data.SqlClient" />
<add name="Client_infoEntities" connectionString="metadata=res://*/clientDatabase.csdl|res://*/clientDatabase.ssdl|res://*/clientDatabase.msl;provider=MySql.Data.MySqlClient;provider connection string=&quot;server=127.0.0.1;user id=root;password=itplustest;persist security info=True;database=Client_info&quot;" providerName="System.Data.EntityClient" />
</connectionStrings>

and also I have added the code below to the web. 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.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>

My connector/net version is 6.7.4.0 and i have MySQL for Visual Studio 1.0.2, I hope you guys could help me to solve my problem.

Thanks JY

1
  • I see nothing in the code you've provided called "client_test.client", so perhaps first you need to figure out what is trying to be instantiated, then you can figure out why it's not working. Commented Sep 21, 2013 at 9:46

3 Answers 3

1

I have been "playing" (In fact, it might be more appropriate to say "fighting") with this MySql thing with CodeFirst in Visual Studio. In fact it does work, but by difference with different readings found in googling around, I am still unable to have code first create its tables.

Anyway, I discovered you have to be very carefull about which version of Entity Framework you are using related to which version of MySql Connector.

I made a very simple console application, which is working fine after I manually created the table.

I am using EntityFramework 5.0 (current version) with the 6.7.4 (beta) version of the connector (Nuget Console PM> Install-Package MySql.Data.Entity -Pre) as this version works with EF 5, while the current version of the connector works with EF 4.2.

Here is my App config. Notice there is no (as in NO) reference to Entity Framework anywhere in this config file.

<?xml version="1.0" encoding="utf-8"?>
<configuration>  
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <system.data>
    <DbProviderFactories>
      <remove invariant="MySql.Data.MySqlClient" />
      <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description="Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="MyContext" connectionString="server=localhost;User Id=bernard;Password=some pwd; Persist Security Info=True;database=test" providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
</configuration>

Hope this helps a bit. I am going to continue looking to see if Code First really works or not with MySql, as with MS SQL Tables and columns are created directly by code first if they don't exists.

EDIT A FEW HOURS LATER ** I finally was able to have code first create the table and columns, yepee! :-)

I explicitly called Database.SetInitializer, which I thought was not needed. Anyway, "REAL" Code First with MySql is now working just fine.

I wrote a blog post about this, and you can download the project from this post: http://www.bgsoftfactory.net/entity-framework-with-code-first-and-mysql-5-6-14-current-version/

Sign up to request clarification or add additional context in comments.

2 Comments

may have a coyp of ur project Thanks!
Sure! I don't know if I can upload a file here. If I can't I'll put it on my web site and let you know here.
0

Have you been able to create a data connection from Visual Studio/Server explorer ? I also see that your default connection point to LocalDB (MSSQL), which might be what you want, but I would keep it as simple as possible to start.

Have a look there, it may help you: http://blog.jongallant.com/2013/04/mysql-aspnet-mvc-entity-framework.html#.UjmwVMbKEqI

Regards, Bernard

7 Comments

Hi, Bernard, I was able to create the data connection form Visual Studio/Server Explorer, but when i tried to created a controller, it gave me the error as mentioned above.
and i am now only using MySQL, so, do i need to remove the default connection?
Hi, Bernard, I have tried the method from the link that you provided, but it gave me the same error msg. i would appreciate if you could help me to figure it out, thank you!
Give me some time, I'll make a test. BTW, yes, you should remove everything not MySQL related, will make it easier on you.
Also, it's not clear to me, and I would like to know so that my test will be closer to your context: Are you using Code First, or Data first? I mean, did you import an existing database structure in your project for EF, or do you define the database structure from within your application ?
|
0

I Had the same issue recently,My error was "There was an Error running the selected code generator:Unavble to retrive metadata for(my application)". I just copied and paste a working controller and change the inside of it.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.