2

I have setup two configuration for migration one is for SQL server and another is for MySql. SQL Server migration is now not being used. Now my problem is when I execute Sql Server migration with Update-Database -ConfigurationTypeName InTouchEnterprise.Data.Repository.MySqlMigrations.Configuration -verbose. It gives me following error

Authentication to host 'localhost' for user 'test' using method 'mysql_native_password' failed with message: Access denied for user 'test'@'localhost' (using password: NO)

But If I run the project it gets successfully connected to the database and do all the operation with database correctly. Now I am clue less what could have been wrong.

According to the error message it says that I am not specifying the password but I have specified password in the web.config. below is my connection string.

<add name="IdentityDB" providerName="MySql.Data.MySqlClient"
connectionString="server=localhost;port=3306;database=rtd;uid=test;password=*******" />

Below is code for Configuration class:

internal sealed class Configuration : DbMigrationsConfiguration<InTouchEnterprise.Data.Repository.InTouchEnterpriseDbContext>
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = false;
        MigrationsDirectory = @"MySqlMigrations";

        //for mysql
        SetSqlGenerator("MySql.Data.MySqlClient", new MySql.Data.Entity.MySqlMigrationSqlGenerator());
    }

    protected override void Seed(InTouchEnterprise.Data.Repository.InTouchEnterpriseDbContext context)
    {
    }
}
10
  • can you try this connection string instead connectionString="Server=localhost;Port=3306;Database=rtd;Uid=myUsername;Pwd=myPassword;" I think it's the connection string format that is invalid.
    – jmesolomon
    Commented May 15, 2018 at 3:19
  • Do you have the right target project set when you run the migration through the package manager?
    – S.C.
    Commented May 15, 2018 at 3:41
  • @jmesolomon Trying that connection string does not change any thing. It gives me same error. Commented May 15, 2018 at 3:42
  • @S.C. Yes I am sure I have right nuget package and startup package as -verbose flag logs are pointing to correct database. Commented May 15, 2018 at 3:43
  • Have you tried changing the connection string to a different database or user just to make sure your package manager is actually referencing the correct connection string and not a default-named one?
    – S.C.
    Commented May 15, 2018 at 3:46

1 Answer 1

2

I don't know the exact issue but when I added persist security info in connection string in web.config to true it started working again. Here is my updated connection string.

<add name="IdentityDB" providerName="MySql.Data.MySqlClient" 
connectionString="server=localhost;port=3306;database=rtd;uid=root;password=*****;persistsecurityinfo=True" />
1
  • Even with EF Core (2.2.0) this solution worked for me Commented Dec 21, 2018 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.