Alexandru Banaru
Alexandru Banaru

Reputation: 11

Cannot configure MySql connection with .Net Core template

I have a problem with my connection to MySql database. I generated an app with ASP.NET Core with target version .NET Framework 4.6.1.

My connection string looks like this:

"ConnectionStrings": {
   "Default": "server=localhost;port=xxxx;database=MmpDb;user=user;password=***;" },

I added MySql.Data.Entities references for Mmp.EntityFrameworkCore and Mmp.Web.Host

I overwrite EF DbContext:

public class MmpDbConfiguration : DbConfiguration
    {
        public MmpDbConfiguration()
        {
            SetDefaultConnectionFactory(new MySql.Data.Entity.MySqlConnectionFactory());
            SetProviderServices("MySql.Data.MySqlClient",
                new MySqlProviderServices());
        }
    }

When I run the command dotnet ef database update I get an error that Keyword not supported: 'port'.

Can somebody provide a solution for this issue please?

Thanks

Upvotes: 0

Views: 756

Answers (2)

Tamim Ehsas
Tamim Ehsas

Reputation: 47

Try to install these packages to your solution

Mysql.Data
Mysql.Data.EntityFrameworkCore

and then try to connect to mysql

Upvotes: 0

ismcagdas
ismcagdas

Reputation: 96

Since Entity Framework Core is new, there is not much mature drivers. I suggest you to use Pomelo.EntityFrameworkCore.MySql for MySql connection.

Then, delete all migration files becasue they are generated agains MsSql. Then regenerate migration files using Add-Migration command and it should work.

You can also check related issue on ABP's github repository here https://github.com/aspnetboilerplate/aspnetboilerplate/issues/2267.

Upvotes: 1

Related Questions