简体   繁体   English

使用Visual Studio连接远程Mysql数据库

[英]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. 我在Visual Studio中有一个与mysql中的数据库连接的应用程序,我在使用wamp服务器。 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? 首先,在本地连接良好,但我的问题是,如果我想将此应用程序与不在本地的其他地方的远程mysql数据库连接,该怎么做?

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. 我试图将其他PC上的IP放入,但不起作用。 The other PC has the same VS application and work as fine as mine locally. 另一台PC具有相同的VS应用程序,并且在本地可以正常工作。

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. 我试图修改一些用户在其他帖子中建议的wamp文件,但是这些都不起作用。

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. 因此,我唯一拥有的就是来自具有该数据库的其他PC的IP。

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. 检查是否允许您的客户端PC访问服务器PC。 Can you ping server PC from the client PC? 您可以从客户端PC ping服务器PC吗? This is not completely definitive, as firewall on the server PC may be blocking pings, but not TCP connections. 这不是完全确定的,因为服务器PC上的防火墙可能阻止ping,但不能阻止TCP连接。
  2. Check your MySQL server user permissions. 检查您的MySQL服务器用户权限。 Chances are it allows only local root access, I think it's default. 可能它只允许本地root用户访问,我认为这是默认设置。 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. 您可以在客户端计算机上使用MySQL Workbench来检查问题是否出在代码中或外部。 If Workbench has problems too, there are configurations issues, such as listed above. 如果Workbench也有问题,则存在配置问题,例如上面列出的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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