简体   繁体   中英

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. So, I need to connect that database using 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. Basically, the topology is: Application's Computer - Access point - Internet - Access point - Server with private 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. 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. 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.

Example

Request on Port 3306 -> Public AP -> Forward Rule (3306 to LAN IP 192.168.1.105) -> Request forwarded to 192.168.1.105

Without the rule, the AP will just drop the request because it want's nothing to do with it

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