-2

I am using MySql database in ASP .NET using C#. When I am trying to connect to any of the databases of MySql it's giving exception of "Access denied for user root@localhost (using password NO)"

Connection string : MySqlConnection con = new MySqlConnection(@"server=localhost;User Id=root;database=sample"); I am using root with password...still it's saying NO Password

1 Answers1

1

Since connecting seems to be the crux of your problem, be sure to use a connection string in the form:

string server = "XXX";
string database = "XXX";
string uid = "XXX";
string password = "XXX";
string connectionString =
    "Server=" + server + ";" +
    "Database=" + database + ";" +
    "Uid=" + uid + ";" +
    "Password=" + password + ";";

I've answered another question about using MySQL from C# that may be of further help by providing a little more context.

Also, be sure to print out or inspect connectionString with your debugger if you still have trouble. Sometimes an error like you're seeing comes down to a simple flub that only becomes clear when you look at the full connection string you've built...and find that it is not what you expected.

Finally, be sure to test with a MySQL client too if trouble connecting persists. As with looking at the connection string you've built to find a simple mistake, sometimes a credentials test outside of your code with a trusted client will reveal that the credentials...truly do not work like you expected.

Community
  • 1
  • 1
J0e3gan
  • 8,287
  • 9
  • 48
  • 76