Hi There,

This comes under a few forums on DaniWeb, so I've guessed and posted it here...

I have two computers, both connected to the internet and running Windows 7 (Home Premium + Professional).

One is my main one, the other is one I do not use.

If I installed say, SQL Server, on the old machine, is there a way of connecting them together so I can access the databases via C#?

Thanks guys,
Matt

Edited 2 Years Ago by mattster

Mattster, yes, you can access SQL Server with C# in your home, office or internet.

The PC with SQL Server installed must have the firewall settings to permit the connection.

So how do I setup the firewall so I can access it internally (without everyone on the internet getting access)

Thanks very very much!

If you have a typical consumber based internet connection (DSL, broadband), you were likely assigned one IP address. This "typical" Internet connection then requires that you have some type of modem/consumer based router running "NAT", or Network Address Translation. Basically, it maps the public IP address for all of your internal addresses. The beauty is that by default, the mapping occurs on outbound traffic, and not inbound unsolicited traffic meaning that someone from the Internet would not be able to get into your private network, unless you created port forwarding rules to map the public IP address directly to an internal IP/Port.

So if you want to gain access to your internal SQL service from the Internet, you need to create a port forwarding rule to allow traffic on port 1433 to this internal device, but that also allows everyone else to do the same. You can only lock it down to a specific computer on the Internet if your router allows the rule to includes specfic external IPs.

Or, you can allow all traffic from the Internet to this SQL box using the port fowarding and run a local firewalll on the SQL server and use the server's firewall application in conjuction with your SQL authentication to allow access.

If you are not that comfortable in this space, you may consider avoiding this altogether and go with a hosting provider.

Edited 2 Years Ago by JorgeM

Yep I have a router (to which both PCs are connected) and that is connected to a modem and the internet.

Thanks very much @JorgeM, so will i have to use port forwarding even if I dont want to access it from the internet, just within a local network?

Thank you!!

No port forwarding is needed on the router if you will be accessing the target host from within the network.

You only have to be concerned with the local firewall settings on the hosts themselves. If they are running windows, you can get their via control panel.

Okay thankyou, so all I have to do is play with the control panel firewalls to allow the computers to talk to each other and I can access SQL Server from C#?

Thanks for all of your help!

Yes, mattster, it's quite simple =)

Just keep in mind that if you have more than one instance installed on your DB Server, you'll need to enable SQL Browser and use the instance to connect.
Examples:

  • 192.168.0.120\SQLServer2008InstanceName
  • 192.168.0.120\SQLServer2005InstanceName
  • 192.168.0.120\SQLServer2003InstanceName

Another thing to bare in mind is the login method. If you're going to use Windows Authentication you'll need to use a valid user account in the DB Server.
Example: If you are using ASP.NET hosted on IIS:

<identity impersonate="true" 
          userName="dbserverdomain\username"
          password="password"/>

If you're going to use SQL Server Authentication, it's quite simpler, just set User Id and Password at the connection string.

Edited 2 Years Ago by AleMonteiro

This question has already been answered. Start a new discussion instead.