19

Trying to connect to MySQL on my web host, using Connector/Net C#/WinForms in Visual Studio 2012 Update 3, but getting the below error message:

Authentication to host '1.1.1.1' for user 'username@mydomain.com' using method 'mysql_native_password' failed with message: Access denied for user 'username@mydomain.com'@'2.2.2.2' (using password: YES)

string connectionString = "SERVER=1.1.1.1;PORT=3306;DATABASE=databaseName;UID=username@mydomain.com;PASSWORD=mypassword;";

MySqlConnection connection = new MySqlConnection(connectionString);
connection.Open();

I am connecting remotely, have whitelisted my IP (and even temporary whitelisted all (%) to test), triple checked the username and password and IP.

I originally tried the username without the domain ( username rather than username@mydomain.com) but it gave me the below error:

Authentication with old password no longer supported, use 4.1 style passwords.

Any assistance would be much appreciated, thanks!

Badger Sharescott
  • 213
  • 1
  • 3
  • 5
  • 1
    possible duplicate of [Authentication with old password no longer supported, use 4.1 style passwords](http://stackoverflow.com/questions/15772479/authentication-with-old-password-no-longer-supported-use-4-1-style-passwords) – eggyal Jul 15 '13 at 06:44
  • 2
    Not duplicate as the first error message is the problematic one. That second error message was resolved by adding @mydomain.com to the username. – Badger Sharescott Jul 15 '13 at 06:58
  • 1
    Your error messages imply that is correct thing to do, i.e. that your MySQL username does not contain `@mydomain.com`. – eggyal Jul 15 '13 at 07:06
  • I do not have a solution, as I appear to have the same problem, but I did note that in my situation, I was using a URL. If I use the physical IP, then the problem disappears. My current theory is that the problem is either a DNS issue or a firewall issue. – Sarah Weinberger Aug 13 '13 at 17:09

10 Answers10

7

Its problem of 'Remote Database Access Hosts'. "You can allow external web servers to access your MySQL databases by adding their domain name to the list of hosts that are able to access databases on your web site."

MySql access is not granted to IP address of the system at which application is running.(in your case its '2.2.2.2' ).

Note:- '2.2.2.2' is your public IP address.

ramya
  • 2,350
  • 6
  • 31
  • 57
6

Two possible things:

  1. MySQL is case sensitive make sure that the case of Database= in your connection string matches with the actual database name
  2. You may have to grant privileges to the user.

I hope this help you.

Zameer Ansari
  • 28,977
  • 24
  • 140
  • 219
Leonel Maye
  • 111
  • 1
  • 3
1

Check your application settings file (or wherever you have stored the connection string).

In my case the application was using the old connection string (which was not valid). I was assuming that the change I made in the code of the settings file is reflected to the designer (of the settings file). But it was not!

theshinylight
  • 233
  • 4
  • 8
1

After creating a new user in MySQL, in MySQL Workbench "Test Connection" will succeed but the C# MySqlConnection.Open() will throw the same exception and message as the question (tested with localhost and 127.0.0.1 and the local ip address).

The reason is that MySqlConnection.Open() will somehow use SELECT privilege, and you need to at least enable the SELECT privilege for the new user. The error message is misleading.

Nexaspx
  • 371
  • 4
  • 20
jw_
  • 1,663
  • 18
  • 32
0

This might be related to the case of specific Membership SQL Server based instructions on ASP.NET 4.5, workaround is to create new membership in web.config, drop mvc 4 AccountControler and use old from MVC3 more here or in the internet:

http://www.nsilverbullet.net/2012/11/06/using-mysql5-as-membership-backend-for-aspnet45-mvc4-application/

Robert Juz
  • 126
  • 7
0

In my case updated password was not used. I just generated the password using Password Generator and copy it but forgot to click Change Password.

Also check the user is added to the database and has Privileges.

Syed Nasir Abbas
  • 1,722
  • 17
  • 11
0

For me, using the actual IP address instead of the domain name solved the problem

Shadi Alnamrouti
  • 11,796
  • 4
  • 56
  • 54
0

While Whitelisting my Ip on cpanel i had accidentally put a space in there after my ip address.[Should have been handled by them] I added the ip again and it worked.

AnkitKwar
  • 76
  • 9
0

In my case, the problem was misleading as well. Had quite a few windows terminals running "the same" .net app all connecting to a remote MySQL server (installed in a windows server machine). However, only one always popping the specific error when anyone clicked to run the .net application. ODBC test connection passed successfully, and no matter if the error popped, when presing OK the application continued loading successfully finally and then worked fine.But again afterwards , when anyone tried to run in for the first time the message appeared. and I repeat only in this specific terminal! The fix finally came when I noticed, that it was only in this specific terminal with the problem that we had forgotten DHCP enabled! and "although it was given always the same IP" from our IT policies, however it only worked when we disabled DHCP and set this IP, SUBNET and GW, as fixed !

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31858274) – MD. RAKIB HASAN May 30 '22 at 12:57
-1

Check with a program like Navicat that the mysql server user has a native password. Everything is correct but if you are getting this error check the version of the link DLL

This error; Mysql.Data.dll and Mysql Server version mismatch error. Download and install an older version

https://downloads.mysql.com/archives/c-net/

Mysql Version < 4.5

Mysql.Data.Dll version= 6.0.3

  • Check with a program like Navicat that the mysql server user has a native password. Everything is correct but if you are getting this error check the version of the link DLL – Eyub Bayazit Aug 26 '21 at 08:45