mysql 5.7 with entity framework 6 - Access denied for user 'root'@'localhost' (using password: NO)
<p>I am currently working on a MVC project with Entity Framework 6 and MySQL database.</p>

<p>I have already install the following:</p>

<ul>
<li>MySQL.Data v6.9.9</li>
<li>MySQL.Data.Entity v6.9.9</li>
<li>Entity Framework v6.1.3</li>
</ul>

<p>Firstly, I added the connection string with the following in my web.config:-</p>

<pre><code>&lt;connectionStrings&gt;
  &lt;add name="MySQLContext" connectionString="server=localhost;database=db;uid=root;password=xxxxxxxx" providerName="MySql.Data.MySqlClient" /&gt;
&lt;/connectionStrings&gt;
</code></pre>

<p>Then I added the following  with the following:-</p>

<pre><code>&lt;entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6"&gt;
    &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/&gt;
    &lt;providers&gt;
      &lt;provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/&gt;
      &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/&gt;                            
&lt;/providers&gt;&lt;/entityFramework&gt;
</code></pre>

<p>I have this context added in my model:</p>

<pre><code>    public class UsersContext : DbContext
    {
        public UsersContext()
            : base()
        {
        }

        // Constructor to use on a DbConnection that is already opened
        public UsersContext(DbConnection existingConnection, bool contextOwnsConnection)
           : base(existingConnection, contextOwnsConnection)
        {

        }

        public DbSet&lt;LoginUsers&gt; LoginUsers { get; set; }
    }

    [Table("login_users")]
    public class LoginUsers
    {
        public int Id { get; set; }
        public string Username { get; set; }
        public string Password { get; set; }
        public string Name { get; set; }
        public DateTime Created_At { get; set; }
        public bool Active { get; set; }
    }
</code></pre>

<p>Then when I try to register/add a user (demo only):</p>

<pre><code>private static string connectionString = ConfigurationManager.ConnectionStrings["MySQLContext"].ConnectionString;

    public static bool RegisterUser(string name, string username, string password, out string errorMessage)
    {
        string hashedPassword = SHA256Encrypt(password);

        using (MySqlConnection connection = new MySqlConnection(connectionString))
        {
            connection.Open();
            MySqlTransaction transaction = connection.BeginTransaction();

            try
            {
                // DbConnection that is already opened
                using (UsersContext context = new UsersContext(connection, false))
                {
                    // Passing an existing transaction to the context
                    context.Database.UseTransaction(transaction);

                    context.LoginUsers.Add(new LoginUsers()
                    {
                        Name = name,
                        Username = username,
                        Password = hashedPassword,
                        Created_At = DateTime.UtcNow,
                        Active = true
                    });
                    context.SaveChanges();
                }

                errorMessage = "";
                transaction.Commit();
                return true;
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                errorMessage = "Contain error";
                return false;
            }
        }
    }
</code></pre>

<p>All the models and connection string have gotten correctly. The connection string also works well with the traditional MySQLCommand. However, when the code reached this following part:</p>

<pre><code>context.LoginUsers.Add(new LoginUsers()
                    {
                        Name = name,
                        Username = username,
                        Password = hashedPassword,
                        Created_At = DateTime.UtcNow,
                        Active = true
                    });
</code></pre>

<p>It threw following exception:</p>

<p><a href="https://i.stack.imgur.com/CGDgB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CGDgB.png" alt="enter image description here"></a></p>

<p><a href="https://i.stack.imgur.com/XzPvE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XzPvE.png" alt="enter image description here"></a></p>

<p>I have set the correct password for my connection string as well. I also added grant my privileges for my database with 'root'@'localhost'.</p>

<p><a href="https://i.stack.imgur.com/tk48w.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tk48w.png" alt="enter image description here"></a></p>

<p>I now stuck at this part. Searching for solutions in internet and SO but none of them works. Anyone has faced this issue and few free to help me to check possible reason and how to fix it?</p>

<p>Thank you for everyone who kindly able to help this!</p>