从其他计算机连接到 SQL 数据库
我对 SQL 还很陌生,而且我被困在一些可能需要点击几下鼠标才能完成的事情上。
我正在构建的程序将把数据存储在管理工作室上创建的数据库中。在测试应用程序上一切正常。现在的问题是:如果我想从另一台计算机上打开程序,我应该如何连接数据库?我尝试在朋友的计算机上复制测试项目,但它找不到数据库,因为我认为这是显而易见的,因为数据库存储在我的电脑上。
我知道谷歌周围存在数百个这样的问题,但我厌倦了在论坛上阅读复杂的内容。任何帮助将非常感激。
谢谢。
I am pretty new to SQL and I'm stuck on something which is probably a few clicks away.
The program I am building will store the data in the database created on the management studio. Everything works fine on a test application. Now the question is: how should I connect to the database if I want to open the program from another computer? I tried copying the test project on a friend's computer but it cannot find the database as I suppose is obvious because the db is stored on my pc.
i know hundreds of questions like this exist around google but I'm sick of looking at forums reading complicated stuff. any help will be really appreciated.
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在数据库连接设置或脚本中,您可能将数据库服务器设置为“localhost”。
如果其他计算机位于同一网络内,请尝试将其设置为计算机网络 IP。
要从网络外部(通过 Internet)连接到它,您需要将数据库服务器设置设置为外部 IP,并且必须将 SQL Server 端口端口转发 (NAT) 到您的计算机。
如果您可以告诉我们您在数据库中使用什么数据库软件,我可以告诉您要转发哪个端口,有关转发的更多帮助,您应该在 serverfault.com 上询问,并提供您的路由器/防火墙品牌和型号
In the database connection settings or script you propably have database server set to 'localhost'
Try setting this to the computer network IP if the other computer is inside the same network.
To connect to it from outside the network (over the internet) You need set the database server setting to you external IP and you have to port-forward (NAT) the SQL server port to your computer.
If you can tell us what database software you are using for the Database I can tell you what port to forward, for more help with forwarding you should ask on serverfault.com and also provide your router/firwall make and model
它首先取决于(至少部分地)您如何连接到数据库。通常,您将拥有某种连接字符串来告诉要连接到哪台计算机。默认情况下,它将设置为本地计算机,但将其更改为其他内容通常只需将该计算机名称编辑到字符串中即可。
如果您通过 ODBC 连接,程序将仅指定 ODBC 连接,并且 ODBC 连接将指定要连接的计算机。您可以使用“数据源 (ODBC)”控制面板来编辑这些(根据您使用的 Windows 版本,它可能位于“管理工具”文件夹中,而不是直接显示在控制面板中)。
It depends (at least partly) on how you're connecting to the database in the first place. Normally, you'll have some sort of connection string that tells what computer to connect to. It'll be set to the local computer by default, but changing it to something else is normally just a matter of editing that machine name into the string.
If you're connecting via ODBC, the program will just specify an ODBC connection, and the ODBC connection will specify the machine to connect to. You can use the "Data Sources (ODBC)" control panel to edit these (depending on the version of Windows you're using, it may be in the "Administrative Tools" folder instead of showing up directly in the control panel).
当您想通过网络连接到 sql 服务器时,您应该了解/检查以下几件事:
为了确保此功能有效,您可以做的最好的事情是尝试使用 sql 从新电脑连接到远程数据库Management Studio,或者如果您不想安装 ssms,您可以尝试创建连接到远程 PC 的 odbc 配置文件。通过执行此操作,您可以确定问题是出在数据库本身还是您的应用程序。
when you want to connect to a sql server over the network there are a few things you should know/check:
To make sure this al works the best thing you can do is try to connect from the new pc to the remote database using sql management studio or if you don't want to install the ssms you can try to create an odbc profile that connects to the remote pc. By doing this you can determine if the problem is with the database itself or with your application.