简体   繁体   中英

Connect a remote Mysql database with Visual Studio

I have an application in Visual Studio that connects with a database in mysql, I'm using wamp server. In the first place works fine connected locally, but my question is what do I have to write/do if I want to connect this application with a remote mysql database in other place that is not local?

Here is the code that I have to work locally:

public static MySqlConnection ObtenerConexion()
    {
        MySqlConnection conectar = new MySqlConnection("server=127.0.0.1; database=tarjetas; Uid=root; pwd=;");

        conectar.Open();
        return conectar;
    }

I tried to put the IP from the other Pc and doesn't work. The other PC has the same VS application and work as fine as mine locally.

None of those databases has an user or password. I tried to modify some wamp files that some users advice in other posts, but nothing of that worked.

Another thing that I have to say it's that I'm proficient with the network configurations. So the only thing that I have, is the IP from the other Pc that has the database.

What else do I have to do to make that connection remotely?

  1. Check if your client PC is allowed access to the server PC. Can you ping server PC from the client PC? This is not completely definitive, as firewall on the server PC may be blocking pings, but not TCP connections.
  2. Check your MySQL server user permissions. Chances are it allows only local root access, I think it's default. Create new user for remote access. Be sure to use non-empty passwords for all users!
  3. You can use MySQL Workbench on your client computer to check if problem is in your code or outside. If Workbench has problems too, there are configurations issues, such as listed above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM