0

I have a fresh new application that now I'm supposed to install in another computer, I'm connected to the same network, and the application runs fine in my computer, but not the others I get System.InvalidOperationException: Connection must be valid and open, the server has the DB and I'm able to connect to the server using its ip, however the other computer is not, it connects properly if I put the ip that the server has by default on the same subnet its ip is 192.168.1.130 however the ip I use in my computer is 220.104.1.X and it connects fine but in the other no, I'm doing something wrong? the connection string is as follows:

    myConnectionString = "Server=201.122.204.102; Port=3306; Database=basedatos; Uid=root; Pwd=root;";
Zenoheld
  • 37
  • 1
  • 14

3 Answers3

0

You have to make sure that the client application can ping the server. Use cmd and execute ping 127.0.0.1 (replace the IP with the server IP). If the ping is successful, it means that the IP should work in your connection string assuming that you are using the correct port, uid and pwd. If the ping fails, it means that your client cannot connect to the server IP. You might need to coordinate with your network administrator to resolve this. What you could try is to use the server name instead of the server IP such as Server=MYSERVER; Port=3306; Database=basedatos; Uid=root; Pwd=root;. Using the server name is useful for servers with dynamic IP.

UPDATE:

Make sure that remote access is enabled in your mysql server. See this tutorial and/or granting remote access.

Also you can execute this query in mysql:

select user, host, password from mysql.user;

See if there are multiple root users. You have to make sure that all accounts have a corresponding password.

use mysql;
update user set password=PASSWORD("NEWPASSWORD") where User='root';
flush privileges;

There are different possible reason why you are unable to remotely connect to your mysql server which can be user credentials, privilege, firewall and much more.

Community
  • 1
  • 1
jegtugado
  • 5,081
  • 1
  • 12
  • 35
  • The IP is actually static and yeah, actually was my first thought I ping like this – Zenoheld Dec 27 '16 at 23:40
  • The IP is actually static and yeah, actually was my first thought I ping like this ping -A 220.104.1.X and it was succesful. – Zenoheld Dec 27 '16 at 23:41
0

The problem might be because of Remote Database Access Hosts. You need to allow the external web servers to access your MySQL databases by adding their domain name to the list of hosts that are able to access databases on your web site.

By default, all IPs are blocked and must be added to an access list in order to access the server. So, before connecting to MySQL from another computer, the connecting computer must be enabled as an Access Host.

You can add host by following steps

  • Log into cPanel.
  • Under Databases, click the Remote MySQL icon.
  • In the Host field, type in the connecting IP address.
  • Click Add Host.
Mohit S
  • 13,723
  • 6
  • 34
  • 69
0

I think your error is the PORT....i remember when i used port in my connectionstring i got error for days. As soon as i removed the PORT it worked. Apparently the connection string will somewhat know which port to go to.

myConnectionString = "Server=201.122.204.102; Database=basedatos; Uid=root; Pwd=root;"

try that