开发者

Connecting to SQL database from other computers

开发者 https://www.devze.com 2023-02-18 23:55 出处:网络
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 work

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.


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


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).


when you want to connect to a sql server over the network there are a few things you should know/check:

  • is your connection string correct (not localhost)
  • does the remote sql server accept tcp/ip connections
  • does the firewall of the remote compture allow the connection
  • Is the sqlbrowser running on the remote computer (if not you need to specify the port in your connection string.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消