Last post Feb 27, 2015 11:29 AM by Shawn - MSFT
Feb 26, 2015 09:28 AM|bh0526|LINK
I'm experienced in building web sites using VS 2013 but never used mySQL until now. I can't seem to connect to the mySql database I created. Here is my code:
string MyConString = "SERVER=localhost;" +
MySqlConnection connection = new MySqlConnection(MyConString);
MySqlCommand command = connection.CreateCommand();
command.CommandText = "select * from Products";
Reader = command.ExecuteReader();
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() + ",";
On the connection.Open() line I get this error:
[MySqlException (0x80004005): Authentication to host 'localhost' for user 'bobh' using method 'mysql_native_password' failed with message: Access denied for user 'bobh'@'localhost' (using password: YES)]
What am I doing wrong?
Feb 26, 2015 05:18 PM|Lannie|LINK
Replace local host with the current IP address of the development workstation and see if it works.
Keep in mind, that IP address might change now and then if you move around, reboot, etc.
As side note, this always works the best for me if you are in a development environment, like a workstation or laptop.
Uninstall MYSQL and start over.
Install the Microsoft Loopback Adapter as a virtual network adapter (Add Hardware, let me choose, find the loopback adapter in the list).
Configure the loopback adapter with a static IP like 192.168.40.40 (not in the same network as your workstation uses), mask 255.255.255.0 and assign 127.0.0.1 as the DNS address, no gateway address since we are local and IPV6 disabled.
Then in hosts.ini file, add an entry
as a local DNS name you made up.
The disable all other network adapters and install the MySQL database against the loopback adapter network configuration.
The advantage, no matter what your wired and/or wireless network adapters do for IP addressing,
the database is always on its own little internal network with a static IP,
and there is no guessing what the correct IP for host ID of the database might be... it is 192.168.40.40.
Feb 27, 2015 11:29 AM|Shawn - MSFT|LINK
This may be related to the invalid connectionstring. And it may be due to the incorrect password. Which password you are using?