0

This is my connection class for C#, but it doesn't work:

class DB
{
    MySqlConnection connection;
    //Baglanti adında bir bağlantı oluşturdum

    public bool baglanti_kontrol()
    {
        connection = new MySqlConnection("Server=93.89.xx.xx:3306;Database=database_database;Uid=database_userid;Pwd='password';");
        connection.Open();
        return true;
    }
}

I tried to every solution in the same topic.

My server gives permission for my IP address.

I am getting the following exception:

'x.x.x.x' for user 'xx_xx' using method 'mysql_native_password' failed with message: Access denied for user 'xx_xx'@'x.x.x.x' (using password: YES)'

  • Is this a server accessed over the Internet? Note that connecting directly to database servers over a relatively high-latency (5ms+) connection is a bad idea because DB protocols are typically very chatty, which amplifies the effects of latency. – Dai May 21 '17 at 10:34
  • 1
    *"...but it doesn't work..."* – Geoff James May 21 '17 at 10:36
  • MySql.Data.MySqlClient.MySqlException: 'Unable to connect to any of the specified MySQL hosts.' @GeoffJames – Batuhan Atalay May 21 '17 at 10:59
  • @BatuhanAtalay - so, why don't you include this exception in your original question? :) – Geoff James May 21 '17 at 11:00
  • @GeoffJames I'm sorry for that. Can help to fix that problem ? – Batuhan Atalay May 21 '17 at 11:20
  • Possible duplicate of [Unable to connect to any of the specified mysql hosts. C# MySQL](http://stackoverflow.com/questions/17993657/unable-to-connect-to-any-of-the-specified-mysql-hosts-c-sharp-mysql) – Geoff James May 21 '17 at 11:21
  • @BatuhanAtalay - as the top answer on the possible duplicate I have posted suggests, it might be that your parameters are not spaced correctly. A useful site I use to ensure I format connection strings correctly is http://connectionstrings.com – Geoff James May 21 '17 at 11:23
  • @GeoffJames Now i get 'x.x.x.x' for user 'xx_xx' using method 'mysql_native_password' failed with message: Access denied for user 'xx_xx'@'x.x.x.x' (using password: YES)' – Batuhan Atalay May 21 '17 at 11:25
  • @BatuhanAtalay - Long shot - but your `password` in the sample code you have provided is in quotes. Is this a typo in your example, or are you using quotes in the actual code? This might be your issue. – Geoff James May 21 '17 at 11:30

1 Answers1

0

I solve the problem like this

"Server=93.89.xx.xx;Port=3306;Database=database_database;Uid=database_userid;Pwd=password;"

Problem is I didn't define "Port" and my password like 'password'