Entity Framework Connection with Mysql

Asked

Viewed 4,486 times

2

I did the procedures outlined in these questions:

Entity Framework - Bank Compatibility

Error Mysql Connection Asp.net MVC

I installed Mysql.Data.Entities.

My web.config looked like this:

  <connectionStrings>
    <add name="BancoDados" connectionString="Server=xxx;
         Database=xxx;
         Uid=xxx;
         Pwd=xxx;"
         providerName="System.Data.EntityClient"/>
  </connectionStrings>

<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>

But when executing Add-Migration fires the following error:

Keyword not supported: 'server'.

I tried to change the providerName for MySql.Data.MySqlClient, triggered the following error:

The ADO.NET Provider with invariant name 'Mysql.Data.Mysqlclient' is either not Registered in the machine or application config file, or could not be Loaded. See the Inner Exception for Details.

When installing the . Net Connector error:

System.Nullreferenceexception: Object Reference not set to an instance of an Object. at Mysql.Data.Mysqlclient.MySqlProviderServices.Getdbprovidermanifesttoken(Dbconnection Connection) at System.Data.Entity.Core.Common.DbProviderServices.Getprovidermanifesttoken(Dbconnection Connection) at System.Data.Entity.Utilities.Dbproviderservicesextensions.Getprovidermanifesttokenchecked(Dbproviderservices providerServices, Dbconnection Connection) at System.Data.Entity.Infrastructure.Defaultmanifesttokenresolver.<>c__DisplayClass1.b__0(Tuple3 k) at System.Collections.Concurrent.ConcurrentDictionary2.Getoradd(Tkey Key, Func2 valueFactory) at System.Data.Entity.Infrastructure.DefaultManifestTokenResolver.ResolveManifestToken(DbConnection connection) at System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest) at System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection) at System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext) at System.Data.Entity.Internal.RetryLazy2.Getvalue(Tinput input) at System.Data.Entity.Internal.Lazyinternalcontext.Initializecontext()
at System.Data.Entity.Internal.Lazyinternalcontext.get_ModelBeingInitialized() At System.Data.Entity.Infrastructure.Edmxwriter.Writeedmx(Dbcontext context, Xmlwriter Writer) at System.Data.Entity.Utilities.Dbcontextextensions.<>c__DisplayClass1.b__0(Xmlwriter w) at System.Data.Entity.Utilities.Dbcontextextensions.Getmodel(Action`1 writeXml) at System.Data.Entity.Utilities.Dbcontextextensions.Getmodel(Dbcontext context) at System.Data.Entity.Migrations.Dbmigrator.. ctor(Dbmigrationsconfiguration Configuration, Dbcontext usersContext, Databaseexistencestate existenceState, Boolean calledByCreateDatabase) at System.Data.Entity.Migrations.Dbmigrator.. ctor(Dbmigrationsconfiguration Configuration) at System.Data.Entity.Migrations.Design.MigrationScaffolder.. ctor(Dbmigrationsconfiguration migrationsConfiguration) at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffoldrunner.Run() At System.AppDomain.Docallback(Crossappdomaindelegate callBackDelegate) at System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)
At System.Data.Entity.Migrations.Design.ToolingFacade.Run(Baserunner Runner) at System.Data.Entity.Migrations.Design.ToolingFacade.Scaffold(String migrationName, String language, String rootNamespace, Boolean ignoreChanges) at System.Data.Entity.Migrations.Addmigrationcommand.Execute(String name, Boolean force, Boolean ignoreChanges) at System.Data.Entity.Migrations.Addmigrationcommand.<>c__DisplayClass2. <. ctor>b__0() at System.Data.Entity.Migrations.Migrationsdomaincommand.Execute(Action command) Object Reference not set to an instance of an Object.

  • 1

    Installed . Net Connector? http://dev.mysql.com/downloads/connector/net/

  • No, I just installed Mysql.Data.Entities.

  • So install and repeat the test, please.

  • @Ciganomorrisonmendez, the following error: "Object Reference not set to an instance of an Object."

  • This error could be anything. You can please put the Stack Trace in the body of the question?

  • @Gypsy!

  • In this answer here the author of the question has the same problem as you. It may be or a problem of setting the web.config or it is the Nector that has some bug. In the most voted answer has to expand this setting. Could check, please?

  • Thanks @Ciganomorrisonmendez, I got... But now I have another problem... http://answall.com/questions/40138/publicar-aplica%C3%A7%C3%A3o-com-Entity-framework-mysql

  • What was done to solve? I still want to add the answer.

  • @Ciganomorrisonmendez, I installed the . net Connector and let the connectiostring so: <add name="BancoDados" providerName="MySql.Data.MySqlClient" connectionString="Data Source=xxxx; port=3306; Initial Catalog=bancoMySQL; uid=usuarioMySQL; pwd=qwe123qwe;" />

Show 5 more comments

1 answer

4


Summarizing what has been put into comment:

1. Install Mysql . NET Connector

http://dev.mysql.com/downloads/connector/net/

2. Setting up the file web.config as follows:

<connectionStrings>
    <add name="BancoDados" providerName="MySql.Data.MySqlClient" connectionString="Data Source=xxxx; port=3306; Initial Catalog=bancoMySQL; uid=usuarioMySQL; pwd=qwe123qwe;" />
</connectionStrings>

<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>

Browser other questions tagged

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