3 Replies - 1849 Views - Last Post: 27 October 2016 - 07:46 AM Rate Topic: -----

#1 SniperCode   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-September 16

How to connect to a remote mysql server using C#?

Posted 27 October 2016 - 05:17 AM

Hello ! I have a C# Application which would access a MySQL server using WAMP on another computer. I am trying to do it via IP. Here is my Connection String :
server = "192.168.10.221";
database = "restaurantdb";
uid = "root";
password = "";
string connectionString;
connectionString = "SERVER=" + server + "; PORT = 3306 ;" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
mycon = new MySqlConnection(connectionString);

I have another computer in which we are in the same network, but when I try to connect to the Mysql I am not able to connect but locally it works...
What do you think ?

What I have tried:

I published my C# application and then launch it in the other computer so that I will try to connect to mysql but nothing works. But I have to mention that when I put the ip adress in the other computer I can have access to wampserver and phpmyadmin ...

Is This A Good Question/Topic? 0
  • +

Replies To: How to connect to a remote mysql server using C#?

#2 Michael26   User is offline

  • Futurama: Insert funny joke here
  • member icon

Reputation: 414
  • View blog
  • Posts: 1,664
  • Joined: 08-April 09

Re: How to connect to a remote mysql server using C#?

Posted 27 October 2016 - 05:24 AM

The problem is at MySQL Server side, root user doesn't have permissions to connect remotely. To give root user permissions to connect remotely just type this on a mysql command line:

GRANT ALL PRIVILEGES ON *.* TO [email protected]"%" IDENTIFIED BY 'rootPass';

Just change 'rootPass' for your current root password, if root doesnt have password MySQL wont let you connect so you will have to define one for it.
Was This Post Helpful? 0
  • +
  • -

#3 SniperCode   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-September 16

Re: How to connect to a remote mysql server using C#?

Posted 27 October 2016 - 06:28 AM

Even if I change the permission, the same error appears... I got this error "MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts."
Was This Post Helpful? 0
  • +
  • -

#4 SniperCode   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 06-September 16

Re: How to connect to a remote mysql server using C#?

Posted 27 October 2016 - 07:46 AM

My port 3306 was blocked , so I open it in the firewall and it resolved my problem.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1