Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a window application with c# and a website with PHP.

I want to use the same database in both applications.

Website is properly running (Hosted with Linux Server obviously).

I am unable to use the same database in C# window application.

When I try to connection through C#, I get the error...




Access denied for user 'user'@'localhost' (using password: YES)

What I have tried:

MySqlConnection con = new MySqlConnection("Server=localhost; Database=database_name; User=user; Password=password");



//The same configuration is running on website.
Posted
Updated 26-Jul-16 3:22am
Comments
ZurdoDev 26-Jul-16 8:20am    
All you have to do is get the connection string right. That should be very simple.

Try using IP address instead of localhost and mention Port number.

C#
MySqlConnection con = new MySqlConnection(
"Server=127.0.0.1;Port=3306;Database=database_name;Uid=user;Pwd=password;");
 
Share this answer
 
v2
The name "localhost" means "this computer".

Your PHP code is running on a Linux server. The MySQL database is running on the same Linux server, so using "localhost" in your PHP connection string is fine.

Your C# application is (presumably) not running on that Linux server. It's most likely running on a Windows computer. If you ask that code to connect to the MySQL database on the same computer as the C# application, it either won't work, or it won't be connected to the same database instance.

You need to update your C# connection string to specify the correct computer name or IP address of the Linux server which is hosting the database. You might also need to configure the MySQL instance on the Linux box to allow connections from other computers.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900