1

I'm new to this and I can't connect my API with my data base, i'm using .Net Core 3, MySql Server 8.0.18, also I downloaded the Connector/Net 8.0.18 and visual studio 2019. This is my string connection:

"Server=localhost,3306;Database=portaldb;user=****;password=****"

My Startup.cs :

public void ConfigureServices(IServiceCollection services)
    {
        var connection = Configuration.GetConnectionString(Defaultconnection);
        var mappingConfig = new MapperConfiguration(mc => { 
            mc.AddProfile(new MappingProfile());
        });
        var mapper = mappingConfig.CreateMapper();
        services.AddControllers();
        services.AddCors(options =>
        {
            options.AddPolicy(MyAllowSpecificOrigins,
                builder =>
                {
                    builder.AllowAnyHeader().AllowAnyOrigin().AllowAnyMethod();
                });
        });
        services.AddSingleton(mapper);
        services.AddTransient<IDbContext, PortalContext>();
        services.AddTransient<ISqlRepository, SqlRepository>();
        services.AddDbContext<PortalContext>(options => options.UseMySQL(connection));
    }

My DbContext:

public class PortalContext : DbContext, IDbContext
{
    public PortalContext(DbContextOptions options) : base(options)
    {

    }
    private DbSet<UsersModel> Users { get; set; }

    private DbSet<CandidatesModel> Candidates { get; set; }

    private DbSet<UserTypesModel> UserTypes { get; set; }

    private DbSet<CompetenciesModel> Competencies { get; set; }

    private DbSet<JobsModel> Jobs { get; set; }

    private DbSet<SkillsAssessmentsModel> SkillsAssessments { get; set; }

    private DbSet<SkillSetModel> Skills { get; set; }

    ///some methods
}

Here are some screenshots of the usings of my DbContext and the packages that I installed, i'm not sure if those are the right ones or if i'm not using them in the correct way.

Usings of my DbContext

Packages

MySql installations

Right now i'm getting this error

"Internal connection fatal error."

I tried with different connection string getting differents errors and I tried to search for an answer but there's almost no information with MySql, a lot with Sql server but no with MySql.

Edit I change the string connection and the startup but i'm still getting an error

: 'Method 'get_Info' in type 'MySql.Data.EntityFrameworkCore.Infraestructure.MySQLOptionsExtension' from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.18.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.'

Edit 2 Ok i read that Microsoft.EntityFrameworkCore 3 it's not compatible with MySql.Data.EntityFrameworkCore for Entity Framework - 8.0.18so i did a rollback to the Microsoft.EntityFrameworkCore 2.1 and now i'm getting Unable to connect to any of the specified MySQL hosts.

7
  • 2
    That's not a MySQL connection string Commented Nov 28, 2019 at 17:57
  • That's a SQL Server connection string. Even there, Trusted_Connection=True means Windows Authentication which is incompatible with a username/password Commented Nov 28, 2019 at 17:59
  • Does this answer your question? How to form a correct MySQL connection string? Commented Nov 28, 2019 at 18:00
  • options.UseSqlServer(connection)?? Commented Nov 28, 2019 at 18:18
  • ok i change the connection string to "Server=localhost,3306;Database=portaldb;user=****;password=****" and this line in the startup services.AddDbContext<PortalContext>(options => options.UseMySQL(connection)); but it say's that i don't have the method get_Info implemented Commented Nov 28, 2019 at 18:40

2 Answers 2

1

OK, as Panagiotis Kanavos mentioned i was using a wrong connection string so i change it to:

Server=localhost;Database=portaldb;user=***;password=***

also as Dongdong said i was using options.UseSqlServer(connection) instead of services.AddDbContext<PortalContext>(options => options.UseMySQL(connection));

And with that i just have to change some versions, Microsoft.EntityFrameworkCore 3 it's not compatible with MySql.Data.EntityFrameworkCore for Entity Framework - 8.0.18, i did a rollback to Microsoft.EntityFrameworkCore 2.1 and now it works.

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

1 Comment

As you discovered, MySql.Data isn't compatible with EF Core 3.0. If you want to use EF Core 3.0, switch to Pomelo.EntityFrameworkCore.MySql: github.com/PomeloFoundation/…
0

MySql.Data.EntityFrameworkCore supports and is only compatible with EF Core 2.1. For EF Core 3.0 or the latest version use Pomelo.EntityFrameworkCore.MySql

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.