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.
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.
Trusted_Connection=Truemeans Windows Authentication which is incompatible with a username/passwordoptions.UseSqlServer(connection)??"Server=localhost,3306;Database=portaldb;user=****;password=****"and this line in the startupservices.AddDbContext<PortalContext>(options => options.UseMySQL(connection));but it say's that i don't have the methodget_Infoimplemented