2

EDIT: Found this post and this worked, but had to run from Win forms:

Enable Entity Framework 6 for MySql (C#) in WinForms of Microsoft Visual Studio 2013

OP--------------------

I have created a console C# application

  • When I right click on my project,
  • goto Add new Item,
  • I add an ADO.Net Entity Data Model called Model1
  • I then select MySQL connection and hit finish

Nothing happens. It just closes the wizard and does nothing.

Anyone come across this problem?

I have installed the MySQL for Visaul Studio program and have also run this NPM command:

Install-Package Mysql.Data.Entities

My App.config looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <entityFramework>
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>
  <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.8.3.0" />
    </DbProviderFactories>
  </system.data>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.8.5.0" newVersion="6.8.5.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
Community
  • 1
  • 1
Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233

1 Answers1

0

A connection string is needed in order to connect to the database. You don't have that info there.

Assuming that you installed Mysql.Data well, try this code:

    MySqlConnectionStringBuilder conn_string = new MySqlConnectionStringBuilder();
conn_string.Server = "yourserver.com";
conn_string.UserID = "youruser";
conn_string.Password = "yourpass";
conn_string.Database = "yourdatabasename";

using (MySqlConnection conn = new MySqlConnection(conn_string.ToString()))
using (MySqlCommand cmd = conn.CreateCommand())
{    //watch out for this SQL injection vulnerability below
     cmd.CommandText = string.Format("SELECT * FROM Users --Just to test");
     connection.Open();
     cmd.ExecuteNonQuery();
}
Filipe Paulo
  • 134
  • 6
  • I typed all the details into the ADO net Wizard, it failed to start building models from the database. It's probably not the best approach to be trying to build the models and their dependencies myself, best let EF do that... – Jimmyt1988 Apr 29 '15 at 17:26