11 Replies - 836 Views - Last Post: 16 August 2011 - 11:39 PM Rate Topic: -----

#1 Ahmedn1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 22
  • View blog
  • Posts: 553
  • Joined: 04-August 09

Connect to a database on a different network

Posted 12 August 2011 - 05:38 PM

I need my app to connect to a sql server on another network
I tried their router IP (I got it using whatismyip.com) but it couldn't connect
and I know that the router changes the IP each time it connects to the internet

any ideas?
Is This A Good Question/Topic? 0
  • +

Replies To: Connect to a database on a different network

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 994
  • View blog
  • Posts: 2,382
  • Joined: 04-October 09

Re: Connect to a database on a different network

Posted 12 August 2011 - 05:49 PM

Unless they have the ports open for you to access it, and they use some form of dynamic DNS, you aren't going to connect.
Was This Post Helpful? 0
  • +
  • -

#3 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4309
  • View blog
  • Posts: 7,457
  • Joined: 08-June 10

Re: Connect to a database on a different network

Posted 14 August 2011 - 02:23 PM

Not only an open port, but they have to turn the services on from the Sql Server's Configuration Manager (not management studio). It's not usually a great idea to expose a database open to the web, even secured. It's a huge attack surface. The best bet is to make some kind of web service (asmx or WCF, ideally) that your application can consume. It's simpler to expose a web server, and for the most part, less risk-prone than opening a DB.
Was This Post Helpful? 3
  • +
  • -

#4 Ahmedn1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 22
  • View blog
  • Posts: 553
  • Joined: 04-August 09

Re: Connect to a database on a different network

Posted 14 August 2011 - 10:02 PM

the problem is that the router of the network that has the server changes its IP every time it connects to the web
so how can we make it static?
Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5641
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: Connect to a database on a different network

Posted 15 August 2011 - 04:23 AM

??? the router doesn't necessarily have an IP address. In any case, it shouldn't matter to your application.

It looks like you have a SQL Server hosted by an ISP? Or you're trying to use a SQL Server box via a DMZ on your home network via an ISP, which is probably against your terms of service.

You make it static by paying the provider to give you a static IP. Though I honestly wouldn't want to expose an MSSQL box like that. Even if you could get your networking sorted out, it's doubtful a third party is going to want SQL Server management traffic going through.

I could be totally off here. Please explain where the SQL Server is located. How the "changes IP every time" thing works. What is the OS hosting the SQL Server? Do you own all the hardware?
Was This Post Helpful? 2
  • +
  • -

#6 Ahmedn1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 22
  • View blog
  • Posts: 553
  • Joined: 04-August 09

Re: Connect to a database on a different network

Posted 15 August 2011 - 07:42 PM

let me explain more
I'm making an application for a company
the app is networked (uses a centralized sql server ) on the network and the clients connects to it

the company had another (near) branch with a separate network
this branch wants to connect to the same sql server of the headquarters
Was This Post Helpful? 0
  • +
  • -

#7 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Connect to a database on a different network

Posted 15 August 2011 - 11:53 PM

Quote

so how can we make it static?

You would still need Dyn DNS.. (The only way to get a static IP Not really a IP but a computer host name to connect to .)

This is the same way terminal services work , if you want to connect to a remote computer via Terminal Services , that pc need a static ip (Host-Name) , the way i know to achieve that is with DNS

Sql server has its own listening port so all you need to do is get a DNS address and add that address to Data-source in the connection string

So you will most likely have

Data Source=mydsnhostname;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;

or with listing port changed

Data Source=myServerAddress:tcpport;Initial Catalog=myDataBase;User Id=myUsername;Password=myPassword;


Here is a link

http://dyn.com/dns/dyndns-free/

This post has been edited by marinus: 15 August 2011 - 11:56 PM

Was This Post Helpful? 1
  • +
  • -

#8 Ahmedn1  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 22
  • View blog
  • Posts: 553
  • Joined: 04-August 09

Re: Connect to a database on a different network

Posted 16 August 2011 - 09:03 AM

marinus
I registered for a dyn dns from your link
but when I make the connection string like this
SqlConnection cn = new SqlConnection("Data Source=http://testn1.dyndns-remote.com;Initial Catalog=test;");
            cn.Open();



it can't connect to the server

Quote

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)


I tried adding the instance name like this

SqlConnection cn = new SqlConnection("Data Source=http://testn1.dyndns-remote.com\\SQ:EXPRESS;Initial Catalog=test;");
            cn.Open();



but no use

any idea?
Was This Post Helpful? 0
  • +
  • -

#9 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4309
  • View blog
  • Posts: 7,457
  • Joined: 08-June 10

Re: Connect to a database on a different network

Posted 16 August 2011 - 09:23 AM

Again, you can't just point to an IP and expect a SQL Server to connect. First, you'd have to set up port forwarding on your router to make sure the connection is forwarded to your DB server. Then, you'd have to configure your DB to accept remote connections. Google your error message and you'll see dozens of topics explaining that. But still consider what I said earlier.
Was This Post Helpful? 0
  • +
  • -

#10 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5641
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: Connect to a database on a different network

Posted 16 August 2011 - 09:42 AM

Quote

Data Source=http://testn1.dyndns-remote.com;

http:// is a protocol designation and has nothing to do with a database. It would be Data Source=testn1.dyndns-remote.com if it had any potential of working.

If you have to use Dyn DNS, then you're almost certainly screwed. You are almost certainly violating your ISP's TOS and chances of talking to an MS SQL database via some home networked NAT'ed beast are close to nil.

Can you see the box? Forget database connections, can you see it at all? Is it behind a gateway router? Did you put in a DMZ so it has a hope of working. Actually, forget it, if it's NAT'd there's no hope. Even if you forwarded the listening port, you still wouldn't be able to establish a session because those ports are opened dynamically.

You still really haven't given enough to go on, but I'm guessing you're in a place were you simply can't do what you want. Unless you own a public address and are binding to it, you're done.

This post has been edited by baavgai: 16 August 2011 - 09:43 AM

Was This Post Helpful? 2
  • +
  • -

#11 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4309
  • View blog
  • Posts: 7,457
  • Joined: 08-June 10

Re: Connect to a database on a different network

Posted 16 August 2011 - 10:43 AM

And at this point, it goes well beyond C# support to network/database support.
Was This Post Helpful? 0
  • +
  • -

#12 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 135
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Connect to a database on a different network

Posted 16 August 2011 - 11:39 PM

Quote



That address is not right


ALSO:

You must configure the windows firewall to also accept network protocols , so you need to add a "exception" for
sqlserver.exe in you firewall

and as the posters said above , you need to configure you rooter for a IP.

Setting up a network is no easy task if you are just starting to learn it , its almost harder that learning Javascript :) (Believe me , i know from Web-Services)

So there is no way we can give you actual steps and each network is different ,
it's more like trail and error to get a network running..

if you struggle , consider investing in a network expert for a day or two.

Good luck!

This post has been edited by marinus: 16 August 2011 - 11:43 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1