Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using mysql database.
When I create conection with local mysql database it works fine but when I am using server database it don't work.

My local string is:

"server=localhost; database=hello42_new; uid=root; password= hello42@123;"

This connection string works fine but when I use
"server=50.62.22.158:8085; database=hello42_new; uid=root; password= hello42@123;"

then it doesn't communicate with database and shows the error:

"Unable to connect to any of the specified MySQL hosts."

Please telll me how can i resolve it.

My code is:

C#
MySqlConnection con = new MySqlConnection("server=50.62.22.108:8085; database=hello42; uid=root; password= hello42; ");

 MySqlCommand command = con.CreateCommand();
 command.CommandText = "select * from login";
 con.Open();
 MySqlDataReader Reader = command.ExecuteReader();
 while (Reader.Read())
 {
     string name = "";
     string pass = "";
     if (!Reader.IsDBNull(0))
         name = (string)Reader["userName"];
     pass = (string)Reader["userPass"];
 }
 MessageBox.Show("success");
 Reader.Close();
Posted
Updated 30-Sep-14 22:06pm
v3
Comments
BillWoodruff 1-Oct-14 2:36am    
Have you put a break-point in your code and single-stepped through it, and it always fails at the same place ?
Rahulmishra011 1-Oct-14 2:41am    
yes it is always fail on same place ,i used break point
it is alway fail on con.open()

Try simply replacing colon ":" with comma ","
50.62.22.108:8085
50.62.22.108,8085

And immediately change the password since you just put it public :) Next time replace your real connection string with changed values myPassword, MyUID or something.

Just friendly advice :)
 
Share this answer
 
Comments
Rahulmishra011 1-Oct-14 3:22am    
ok i try ,its not the real username and password.......just it sample
thanks to suggest
Rahulmishra011 1-Oct-14 3:23am    
its not working when i use , place of:
Sinisa Hajnal 1-Oct-14 3:41am    
Sorry. And good about changing password and user name they looked real :)
Rahulmishra011 1-Oct-14 3:50am    
its ok
2 things:

- Remote access is not allowed by default to root user. It's not a good idea,but you can enable it by running this command:

SQL
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;


- On the other hand, check my.cnf file, find this line
bind-address = 127.0.0.1
and comment it out.

Hope it helps
 
Share this answer
 
v2
Comments
Rahulmishra011 1-Oct-14 4:14am    
i tried it bt problem is not solve
Pikoh 1-Oct-14 4:15am    
did you restart server after following this steps?
Rahulmishra011 1-Oct-14 4:25am    
thanks alote for use this command i accived it
Pikoh 1-Oct-14 4:28am    
If it helped you please mark solution as accepted so it could help others having the same problem
Rahulmishra011 1-Oct-14 4:48am    
yes

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