Jenish Rabadiya
Jenish Rabadiya

Reputation: 6766

Entity framework code first with MySql server not able to run migration

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)
    {
    }
}

Upvotes: 2

Views: 1743

Answers (1)

Jenish Rabadiya
Jenish Rabadiya

Reputation: 6766

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" />

Upvotes: 2

Related Questions