简体   繁体   English

如何通过Internet将.net应用程序连接到SQL Server

[英]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). 我已经创建了一个具有登录表单的C#应用​​程序(我使用SQL Server数据库和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". 该数据库位于我的PC上,当我在与我的同一个网络中的另一台PC上运行程序时,一切正常,但是当我在另一网络上连接一台笔记本电脑时,会出现错误:“路径不正确找到”。

Is it possible to connect with the server remotely, via internet or something, without having to be on the same network? 是否可以通过Internet或其他方式远程连接服务器,而不必位于同一网络上?

I already have: 我已经有了:

  1. Opened tcp and udp ports 打开TCP和UDP端口
  2. Allowed SQL Server ports in Windows Firewall Windows防火墙中允许的SQL Server端口
  3. Added an inbound rule for tcp (port 1433) and udp (port 1434) 为tcp(端口1433)和udp(端口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. 要使服务器可以在Internet上访问,是一项昂贵的工作。 The static IP adress alone will cost a pretty penny, never mind actuall hardware. 仅静态IP地址将花费相当多的钱,不用担心实际的硬件。

On a small/no budget, VPN is perhaps the only way. 在很少/没有预算的情况下,VPN可能是唯一的方法。 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. 通过VPN,您可以连接两个本地网络(路由器的本地网络),使设备可以像在物理上位于同一网络中一样进行通话。

No change to the programm is nessesary. 无需更改程序。 If it works local, it works over VPN. 如果在本地工作,则可以在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. 用户将必须连接到您必须提供的VPN端点-通常可以通过任何像样的路由器以便宜的价格提供。

First off you should definitely change that PW. 首先,您一定要更改该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? 另外-您做出的评论是您试图使用同一程序从不同的网络连接-暗示您尚未更改IP地址...确定要使用公共IP地址吗? (Not your local network one that will start with 10. / 172. / 192. (不是您的本地网络以10. / 172. / 192.开头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. 确保您使用的是公共IP地址...即使这样做,即使您在同一网络中,也会将其视为不使用。 It seems to me like you're still trying to use the local network's IP. 在我看来,您似乎仍在尝试使用本地网络的IP。

If it persists make sure you can reach the PC itself: ping ip-of-host in Powershell. 如果仍然存在,请确保您可以访问PC本身:在Powershell中ping ip-of-host

Connecting C# with SQL Server Database in a Local Area Network (LAN) 将C#与局域网(LAN)中的SQL Server数据库连接

Try these steps one by one : 一步一步尝试这些步骤:

1- Find your public IP address using ( www.whatismyip.com ) for example. 1-例如,使用(www.whatismyip.com)查找您的公共IP地址。

2- Check that you can connect to the database using the public IP. 2-检查您是否可以使用公共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 为此,请转到SSMS,并在服务器名称中尝试仅使用IP地址或“ IP地址\\ [实例名称]。如果不起作用,则必须首先解决此问题。检查此: 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. 3-步骤2起作用时,您可以在连接字符串中使用“ IP-地址\\ [实例名称]”。

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

相关问题 如何通过互联网连接SQL Server? - How to connect sql server through internet? 如何从.NET应用程序连接到SQL Server Compact? - How to connect to a SQL Server Compact from a .NET application? 如何将应用程序连接到另一台计算机上的SQL Server? - How can I connect my application to a SQL Server that is on another computer? Windows Mobile-.NET CF:如何通过PC连接到Internet? - Windows Mobile - .NET CF: How to connect to the internet via PC? 如何通过 inte.net 连接到远程 SQL Server Express? - how to connect to remote SQL Server Express over internet? 如何从在容器中运行的 ASP.NET 核心应用程序连接到具有集成安全性的 Windows 服务器上的 SQL 服务器 - How to connect from ASP.NET Core application running in a container to SQL Server on Windows Server with Integrated Security 使用我的应用程序在.NET中部署Sql Server - Deploy Sql Server in .NET using my application 如何在C#应用程序上连接到SQL Server - How to connect to sql server on c# application 如何通过网络连接到SQL Server数据库? - How to connect to a sql server database over the net? 通过Internet连接MySQL和.net应用程序有危险吗? - Is connecting MySQL and .net application via Internet a hazard?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM