Home > database >  C# - connecting to a MySQL database in a remote computer
C# - connecting to a MySQL database in a remote computer

Time:11-29

Good day; I am making an C# desktop application using MySQL as database. The execution works fine when using local server "localhost", but I want to install it in other computers and keep the database in my computer. I proceeded like following to allow other computers to connect the database :

  • I added a new user to the database and gave it all required permissions.
  • I added the IP address of the computer in which the database exist This is the connection string :
String connString = "Server = '192.168.xxx.xxx';  "
                       "Port = '3306'; "
                       "Database = 'mydb'; "
                       "uid = 'dbUser'; "
                       "pwd = 'userPassword';"
                       "Persist Security Info=true;";

From the computer in which the database is installed, I can execute without any problem but from other computers I can not connect to the database. It gave me the error :

Unable to connect to any of the specified MySQL hosts.

  • Computers are in network but not in the same domain network.
  • There is no problem with the port.

Can anyone help me please ?

CodePudding user response:

Finally, I resolved the problem. The problem was the port 3306 should be authorized by the firewall of the computer in which the database is installed. For those who got the same problem, this is the way how to resolve it :

  • Open firewall >> Advanced settings
  • Right click on Inbound Rules and choose the first option New Rule.
  • Check the second option Port, then click Next button
  • Be sure that TCP option is checked, then check Specific local ports and add the port 3306. Then Next and the port 3306 will be authorized and the connection from other computers permitted.
  • Related