Error Mysql Connection Asp.net MVC

Asked

Viewed 406 times

4

I am trying to work with a Mysql database in my application. However, I am getting the following error:

Keyword not supported: 'data source'.

I performed all the procedures related in this question But in summary, I performed this installation in my NuGet

PM> Install-Package MySQL.Data.Entities

Web.config

  <connectionStrings>
    <clear />
    <add name="BancoDados" connectionString="Data Source=mysql01.hospedagemdesites.ws;
         Initial Catalog=catalog;
         User ID=userid;
         Password=password;"
         providerName="System.Data.EntityClient" />
  </connectionStrings>

App.config (Repositorioef)

 <entityFramework>
    <defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
    <providers>
      <provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
    </providers>
  </entityFramework>

Context

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class Contexto : DbContext
{
    public Contexto()
        : base("BancoDados")
    {
    }
    public DbSet<item> item { get; set; }
}

2 answers

3


Data Source is for SQL Server. Modify to:

  <connectionStrings>
    <clear />
    <add name="BancoDados" connectionString="Server=mysql01.hospedagemdesites.ws;
         Database=catalog;
         Uid=userid;
         Pwd=password;"
         providerName="MySql.Data.MySqlClient" />
  </connectionStrings>
  • I changed the provider as he had recommended me in the other question. With it so : providerName="MySql.Data.MySqlClient" I was able to go ahead and find myself now with another mistake. Unknown column 'Extent1.Nome' in 'field list'

1

Put it like this:

Direct Connectionstring in Constructor

[DbConfigurationType(typeof(MySql.Data.Entity.MySqlEFConfiguration))]
public class Contexto : DbContext
{
    public Contexto()
        : base("Server=mysql01.hospedagemdesites.ws;Database=catalog;Uid=userid;Pwd=password;")
    {
    }
    public DbSet<item> item { get; set; }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.