Error connecting to Aurora during Entity Framework Core DB update

0

I am trying to run the dotnet ef database update CLI command against my AWS Aurora MySql RDS cluster. Just for testing purposes, I've hard-coded the connection string to remove configuration loading being an issue.

When I run the update command I'm given the following error:

An error occurred using the connection to database '' on server 'some-rds-cluster.abcdefg.us-east-2.rds.amazonaws.com'.

MySql.Data.MySqlClient.MySqlException (0x80004005): Access denied for user 'bobby'@'555.555.555.555' (using password: YES)

at MySqlConnector.Core.ServerSession.ConnectAsync(ConnectionSettings cs, ILoadBalancer loadBalancer, IOBehavior ioBehavior, CancellationToken cancellationToken) in C:\projects\mysqlconnector\src\MySqlConnector\Core\ServerSession.cs:line 333

My ConfigureServices method looks like this:

public void ConfigureServices(IServiceCollection services)
{
    services.AddOptions();

    services.AddDbContextPool<AccountContext>(options =>
    {
        options.UseMySql("server=a-random-cluster.foobar.us-east-2.rds.amazonaws.com;database=SomeDbHere;user=abcdefg;password=abcdefg", contextOptionsBuilder =>
        {
            contextOptionsBuilder.ServerVersion(new Version(5, 7, 12), ServerType.MySql);
        });
    });

    services.AddMvc()
        .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}

I am able to connect to the cluster using MySql Workbench on my local machine; the update CLI command from the same machine though fails. The Security Group attached to the RDS allows traffic from my IP address to connect (hence why MySql Workbench connects). Is there something specific with EF Core and Pomelo.EntityFrameworkCore.MySql I need to do in order for the CLI to update the tables? Does Aurora support what EF Core needs to do in order to update the data model, such as using a different port number for some reason?

I noticed the error said "using the connection to database' '` and I can't tell if it intentionally left the database name blank or if that is part of the problem. The DB is specified in the migration and connection string though, so I'm would assume they leave the db name out since in MySql it's not a Db but rather a "schema".

I'm running aspnetcore 2.1.0 and EF core 2.1.0

I generated the migrations from my entities and contexts which is below.

public partial class InitialMigration : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.EnsureSchema(
            name: "SomeDbHere");

        migrationBuilder.CreateTable(
            name: "Users",
            schema: "SomeDbHere",
            columns: table => new
            {
                Id = table.Column<int>(nullable: false)
                    .Annotation(
                         "MySql:ValueGenerationStrategy",
                          MySqlValueGenerationStrategy.IdentityColumn),
                Username = table.Column<string>(nullable: true),
                CognitoId = table.Column<string>(nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_Users", x => x.Id);
            });
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropTable(
            name: "Users",
            schema: "SomeDbHere");
    }
}
c#
mysql
entity-framework
amazon-web-services
amazon-rds-aurora

2 Answers

0

I had the same problem and it was because the DB password contained a '$' char in it.

Thus when I did export MY_DB_ENV="Server=localhost;Database=my_db;Uid=root;Pwd=pass_with_$abc" the $abc was stripped from the password and couldn't connect.

You can check with echo $MY_DB_ENV if that's the case.

answered on Stack Overflow Jan 20, 2020 by Guillermo
-1

It seems like a connection issue. I was able to connect and run migrations in a new project. Take a look at this project https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql and read the code in test/EFCore.MySql.IntegrationTests.

answered on Stack Overflow Sep 9, 2018 by Raymond Sanchez

User contributions licensed under CC BY-SA 3.0