简体   繁体   English

将C#与MySQL上的远程数据库连接

[英]Connect C# with remote database on MySQL

I'm trying to connect a MySQL database with a C# application, the MySQL database is mounted on a server in a LAN with access to internet. 我正在尝试将MySQL数据库与C#应用程序连接,该MySQL数据库安装在可访问Internet的LAN中的服务器上。 So, I need to connect that database using C#. 因此,我需要使用C#连接该数据库。 The most of the answers I have found, explain that in the connection string use the IP of the server, but the IP of the server, in this case, is a private IP, the public IP is the IP of the modem or access point, where the server obtain the Internet access. 我发现的大多数答案都说明,在连接字符串中使用服务器的IP,但是服务器的IP在这种情况下是专用IP,公共IP是调制解调器或访问点的IP ,服务器可在其中获得Internet访问。 Basically, the topology is: Application's Computer - Access point - Internet - Access point - Server with private IP. 基本上,拓扑是:应用程序的计算机-接入点-互联网-接入点-具有专用IP的服务器。 Any help or comment will be appreciated. 任何帮助或评论将不胜感激。

If you are on the same LAN as the database server than you should just connect directly to the private LAN ip. 如果您与数据库服务器位于同一局域网中,则应直接连接到专用局域网IP。 If it is going through an access point or your main firewall, then you need to setup the appropriate port forwards between the AP and the private server so that it forwards the port requests appropriately. 如果它正在通过访问点或主防火墙,则需要在AP和专用服务器之间设置适当的端口转发,以便它正确转发端口请求。 If those forwards are not in place, you will not be able to connect to it form the WAN side as the AP needs to know where to forward those requests. 如果没有这些转发,您将无法从WAN端连接到它,因为AP需要知道将这些请求转发到哪里。

Example

Request on Port 3306 -> Public AP -> Forward Rule (3306 to LAN IP 192.168.1.105) -> Request forwarded to 192.168.1.105 端口3306上的请求->公共AP->转发规则(3306到LAN IP 192.168.1.105)->请求转发到192.168.1.105

Without the rule, the AP will just drop the request because it want's nothing to do with it 如果没有规则,则AP只会丢弃该请求,因为它与请求无关

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

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