简体   繁体   中英

How to connect my .net application to SQL Server via internet

I have created a C# application with a login form (I use SQL Server database and SSMS). The database is on my PC, when I run the program on another PC which is in the same network as mine, everything works fine, but when I connect one of the laptops on another network, an error occurs: "The path wasn't found".

Is it possible to connect with the server remotely, via internet or something, without having to be on the same network?

I already have:

  1. Opened tcp and udp ports
  2. Allowed SQL Server ports in Windows Firewall
  3. Added an inbound rule for tcp (port 1433) and udp (port 1434)
  4. Allowed remote connections

Here is my connection string:

Data Source=<server name>;Initial Catalog=Name;User ID=Minko;Password=Password1

This is not a programming question, but a Networking one.

To have a server reachable in the internet, is a costly mater. The static IP adress alone will cost a pretty penny, never mind actuall hardware.

On a small/no budget, VPN is perhaps the only way. Via VPN you can connect two local Networks (the home side of the Routers), allowing devices to talk as if they were physically in the same network.

No change to the programm is nessesary. If it works local, it works over VPN. The network classes do not care if the target is on the same computer, the same Switch or the Voyager probes.

The user will have to connect to teh VPN endpoint you have to provide - and usually can provide for cheap with any decent Router.

First off you should definitely change that PW. Also - you make the comment that you are trying to use the same program to connect from a different network - implying that you haven't changed the IP address... Are you sure you're using your public IP address? (Not your local network one that will start with 10. / 172. / 192.

Make sure you're using your public IP address... if you do this even if you're on the same network it will treat it as if you're not. It seems to me like you're still trying to use the local network's IP.

If it persists make sure you can reach the PC itself: ping ip-of-host in Powershell.

Connecting C# with SQL Server Database in a Local Area Network (LAN)

Try these steps one by one :

1- Find your public IP address using ( www.whatismyip.com ) for example.

2- Check that you can connect to the database using the public IP. To do that go to SSMS, and in the server name try to use IP-address only, or "IP-address\\[instance-name]. If doesn't work, then you have to fix this first. Check this: https://dba.stackexchange.com/questions/62165/i-cant-connect-to-my-servers-sql-database-via-an-ip-address

3- When step 2 works, then you can use the "IP-Address\\[instance-name]" in the connection string.

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