Remote access to SQL Server 2008 R2 [closed] - c#

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
Reminder: Not on local area network. Is there a need some configuration of SQL Server? What connection strings will be used? C#.net is the programming language.

I don't know much about c# or ms sql server 2008 however I have set up many servers
every computer connected to the internet has an address... I'm sure you know that
now, if you use a router you will know that the router is connected to the modem, and is distributed through the router either through a wireless connection or ethernet connection (the cord), the way the router organizes things, is each computer is assigned a private ip address (something like 192.168.1.2)... this private ip address cannot be accessed by the outside world at all... BECAUSE the router gets a packet, and doesn't know where to put it, so it immediatlely drops it (forgets it)
this is really safe, because this means the only way a bad person could reach your computer is if they were on the same network... however, sometimes you need to host a server that NEEDS to be accessed by the outside world...
this is explained in a bit, just read on
now also every internet packet (which is anything sent around a network) goes to a specific port
these are referenced with regular numbers: ie (port 80, 160, 55, et cetera)
the great thing about ports is that different computer programs can handle different ports, at the same time!!!
so a computer can be running multiple servers at the same time. because the corresponding packet is sent to the corresponding port and therefore a packets meant for a specific application won't interfere by another accidentally.
so in conclusion what we need to do is tell our router to say...
is the port equal to the port used in the ms sql server?
if so take the packet and send it to (the private ip address of your server)
this is called Port Forwarding
you'll need to first find the private ip address of your server.
on windows you would need to go in the command prompt and type:
ipconfig
in Linux and Mac OS X
ifconfig
once you find the private ip address of the server. make it a static... meaning it cannot change
you'll have to research this as I do not use Windows
remember: Static IP Address
now once you get a static ip address for your server you'll need the port(s) that ms sql server 2008 uses.
once you find that you need to set up port forwarding on your router
this varies from router to router, however, if you have a Netgear router you can go to the web admin page by pointing your browser to http://192.168.1.1/
this will bring you to the netgear router admin page. find port forwarding/port triggering on the sidebar and click add custom service, then add the input.
Now the last step is to find your public ip address, to tell your friend, this is the address he/she will access the server with
you can find this real easily by going to http://www.ipchicken.com/
this should work
HOWEVER
if you only have a modem and get your internet directly through that. you have a different situation
all the packets get sent to the one computer connected to WAN port (meaning everything gets sent to your computer regardless of port)...
if this is the case
you should forget about port forwarding and just give your friend your public ip found using ipchicken or another method....
this should work, unless ms sql has an extra security layer that I don't no about
hope this helped
EXTRA
Windows by default adds a firewall that blocks all connections, except for the exceptions that are established after a bit of use... so first you will need to punch a hole in Windows firewall by adding an exception... this is done by clicking on the current connection you are using and clicking on properties or something, don't know exactly but once you find out how to do that. it's just a matter of telling the firewall that port "whatever port ms sql uses" is safe.
After that is done, your friend should be able to connect by entering your ip address as the host.... I don't know much about C# as I said, but what your friend would do is use the nessecary procedures as he or she would have if they were connecting to any old sql server. except the "host" is the ip address of your server.
I don't quite know what you mean by connection string, could you try to give me more info on that please?

All SQL servers can connect over tcp/ip and MS is no exception. If your machine is behind a NAT router or a firewall you need only setup the appropriate port access. On most consumer grade equipment this is known as a pinhole. You must allow inbound to the SQL Server port of 1433 or whichever one you choose.
Most ISP's these days give you one WAN ( real world ) IP address and that is the wan side of your router. All machines on the LAN side are normally on a 192.168.x.x / 10.x.x.x / 172.16.x.x address scheme which are not routeable as all routers are programmed to ignore those address blocks and not to pass them on.
Please keep in mind unless you asked specifically for a static IP address your WAN side will most assuredly change from time to time and so you will need to let your friend know what it has changed to via something like ipchicken.com
Additionally since LOTS of attackers look on the standard ports for MS-SQL I highly suggest you use some random port above say 10,000 instead of the standard 1433 if your device does not have the ability to limit the source address.

Related

What is the best way to link my own hardware with my application on a LAN network?

I have hardware based on a microcontroller with Ethernet communication.
There is a TCP server in the microcontroller.
To configure the hardware, I have an application made in C# for android.
The application, in turn, has a TCP client.
For the app to find my hardware, what I'm doing is pinging each of the addresses of the same network segment of my mobile.
That is, if the IP address of my mobile is 192.168.0.xx, I ping from the address 192.168.0.1 to the address 192.168.0.255.
Those addresses that respond, I try to open a socket and send a data frame, if the answer is correct, I assume that I have found a hardware in my local network (there could be more than one connected)
Obviously those IP addresses that don't respond, or that the socket cannot be opened or that they respond to something wrong are discarded.
Those valid addresses are displayed in a list for the user to choose with which to interact.
Also, these valid addresses are saved in the application so that the next time the app is opened, it will automatically connect to the stored addresses, avoiding the scanning of the IP addresses.
This seems correct to me the first time the user installs the hardware and configures with the app
The problem is that I was informed that there are users that their routers are configured to renew their IP addresses once a month.
If this happens, the app should again perform a scan of all the IP addresses again, and this is somewhat cumbersome, since scanning all the IPs takes some time, I don't think users are happy configuring their app and hardware once a month.
Another cumbersome solution could be to use static IP addresses, but I don't think that's a good idea either.
Any suggestions on how to improve this?
You need to take subnets into account. You are assuming that the subnet you are connected to is a /24. You are also pinging the broadcast address (.255) which is unnecessary. A host doesn't reside there.
DHCP assignments will renew their lease halfway through the lease period. If your hardware is still on the network it will most likely get the same IP assigned as it did prior from most modern DHCP implementations.
Finally, consider lowering any timeout values in your scan. Scanning a /24 for hosts to respond on a specific port should complete in seconds.
The solution is explained by #Charlieface in the comments of the question.
I'm going to implement a UDP server on the microcontroller with an IP address within the range of 224.0.0.0-239.255.255.255 (Multicast IP addresses).
When connecting to said server and sending a data frame, the ip and other parameters will be returned so that the app can connect directly to the hardware without having to perform a scan of all the IP addresses.
More details of the solution, in the following freeRTOs thread:
How can I create a UDP server with static IP?

C# - Globally intercept and modify DNS resolution responses

There's a similar question ( Can I temporarily override DNS resolution within a .NET application? ) but I just can't figure it out with the meager response there.
Background info
I have a server set up in my home network, an old computer. Our router has the right ports forwarded, the server runs server software for things like http, svn, games, etc. I've got a domain name registered that always points to our external IP address. For all intents and purposes, I've got a typical webserver set up. My friends can game on my server by connecting via the domain name, I can push and pull svn projects, etc.
The only problem is that I also need to use my server when I'm connected to my home network (the same network as the server). Using the domain name results in Windows resolving it to our own IP address, and my router is too retarded to realize it just needs to forward it back into our network to the server as per the usual. I've done some looking around, configuring, telnetting and DNS overriding, but I have it on good authority that our ISP apparently crippled the DNS override feature of their routers to prevent this exact scenario. Apparently they don't like internal loopbacks.
I now basically have to keep 2 configs for each of my server's services: one config that specifies the domain name for when I'm abroad, and a second that specifies the server's internal IP for when I'm at home. It's frustrating because it just isn't always possible.
I want to instantiate a global DNS resolution request/response listener that will do the following: if the requested domain name matches a given string, override the IP in the response with one of my choice.
I've looked things up like easyhook, dllimport, msdn pages, etc, but I still can't figure out where to actually start, which classes I need to get access to, and so on. I basically have no pre-existing code for this particular problem.
I have Visual Studio, years of relatively simple programming experience and a good understanding of unfamiliar code and everything else, just no idea how to start or what to look for.
Many thanks for anything that can get me going.
Couple of pointers, DNS is as you mentioned some server somewhere that knows how to resolve a Domain name to an IP ADDRESS. There are two types of responses 1) Definitive for the domain and 2) Not Definitive for the Domain. Obviously any Definitive response will win.
DNS does not run at TCP/IP layer it runs one layer below using UDP (port 53). As a result DNS is tied into the TCP/IP stack whereby the stack first looks locally to a local host table and sees is the name is there, if it cannot find it the stack will send out the DNS request prior to the session start or SYN packet flying. In order for this to happen, the DNS servers must resolve the address.
I do not fully understand your issue because most Windows servers only have 1 IP Address and one associated Domain name. Unless of course they are using DHCP which just means the server uses multiple address on boot up and DNS server receive updates to what those new address are.
Public vs. Private IP addresses are the responsibility of a router. The router is configured to do NAT (Network Address Translation). This allows a private server to have unroutable addresses like 10.10.1.100 etc. But the router will answer ARPs for the public address making the public network think the router is the public address. So one of your solutions could be to convert your server to a private address and use a "real" router that can perform NAT. Port forwarding is not really routing rather it's a way to "trick" packets destined for one port number to be forwarded to another port dedicated for that application.
My suggestion is to either follow the suggestions above or add the Domain names you want to the local Host table on the server. This will get you what you want. A better solution is to configure your own server to be a DNS server definitive for your domain, that way you get to control everything.
I ended up solving this with (as a few have suggested) the hosts file after all.
I first used ManagedWifi to set a network connection monitor. It detects changes to my connection status and reports the network name.
Then I wrote a console app that stays open (using Hidden Start allows me to hide the window) and safely modifies the hosts file, then flushes the DNS cache. This seems to work in pretty much realtime. :)

how can i send data over internet to any specific computer in subnet

I want to know how I can send or recieve data over internet to/from a computer in subnet
(this is specially in context to PPP users bcoz getting static IP is not so much in practice).
I actually want to create an application which can transfer file between 2 specific computer in WAN.
so what are things I need to know about to do the same..(ex. PRESENT IP or MAC ADDRESS etc..)
PROGRAMATICAL EXPLANATION ALTHOUGH PREFFERED,BUT IS NOT NECCESARY...
FTP?
There is a vast torrent of useful results in google, I seriously suggest to google before you ask here.
For instance, have a look at the top result: http://www.devarticles.com/c/a/C-Sharp/Network-Programming-in-C-sharp/
Apart from that, FTP, as suggested by Colin, may be what you're looking for. If you're new to using FTP in C# have a look at http://www.google.com/search?q=c%23+ftp
Put the information on a public IP server, so both computers keep polling if there is new data and send / download that data as needed. A single text file can hold necessary flags such as paths and other info you need.
server just need to be a web server, which means IIS or similar should be installed.
I'm thinking part of your question has to do with one of the computers not having a static IP address. If the two computers, A & B, don't know each others IP address, then an alternative is to use a server. Either A can store the information on the server to be picked up by B, or A can register his current IP address on the server for B to lookup and then connect to A, assuming firewalls don't interfere. Another scheme is that A and B can simultaneously connect to the server, and the server can relay data between the two.
Of course, all of this communication would be done using techniques such as those suggested by mafutrct and Colin.
This question sounds to me like the difficulties of NAT Traversal and trying to establish peer-to-peer connectivity over the Internet. I stumbled on this question researching the best way to set up Internet connectivity to a device that is sitting behind a firewall. I am assuming that the device behind the firewall has to initiate the connection, that a Internet server application (on a Public IP address) to at least manage the initiation of the connection is required, and the Internet server application may also have to act as a relay if the difficulties of NAT is not able to be traversed.
http://en.wikipedia.org/wiki/NAT_traversal
http://en.wikipedia.org/wiki/Peer-to-peer
A good example of this is LogMeIn. Where the application is installed on the computer that needs to be accessible over the Internet, that application communicates with the LogMeIn Internet servers, you can establish a connection to that computer either by initiating through the LogMeIn servers and connecting peer-to-peer over port 80/443 using NAT Traversal (this would be establishing a peer-to-peer connection) or by initiating through the LogMeIn server and the LogMeIn server acting as a relay if peer-to-peer is unable to be established.
Please note; you must have an application (something running) on both ends of the connection on the Internet, there is no other way. Just like FTP that was mentioned earlier (FTP Client, FTP Server)... but in this case it is peer-to-peer (basically you are writing your own Client and Server... or if you have to use a relay... Client--Relay--Server
http://en.wikipedia.org/wiki/LogMeIn
"The service connects the remote desktop and the local computer using SSL over TCP or UDP and utilizing NAT traversal techniques to achieve peer-to-peer connectivity when available."
The part I don't know is can the relay go in both directions; and I am figuring the device behind the firewall must have to constantly manage the open connection to the Internet Server that is the relay. Those are the questions I am wrestling with now.
Also, you may want to check out this post.
C# byte streams through TCP
From that time, till this date I have encounter so many problems with these four kinds of NAT that basically without an external server you cant do anything.
This is because, one computer can never find where the other one is located as suggested in the pic.
Here PC 'A' will never come to know about the port that corresponds to PC 'B' on R2B without an external server.Even more, if somehow u come to know about the ports you are still in a situation that the router wont allow you to access it if the request hasn't been made for your IP.

Acquire an IP address from dhcp server for my C# app - Like Virtual Machines

I'm developing an application of multiple socket connections (a TCP alarm watcher). Currently, in order to mock the alarms, i made small applications running on a VM Machine (that is, because the Vm have a different IP) that simulate the alarm endpoints.
What I want to do is to mock the alarms in the same machine I'm running my "server" (i.e. the first application), except that I want these mock alarms to have a different IP. I don't want my mocks running with the same IP that the first App (e.g. The server is 192.168.1.4; I want a mock to be 192.168.1.10, other being 192.168.1.11, etc.; all living in the same machine, just the way VM's can do that).
Virtual Machines in 'bridged network' mode can get a different IP from the DHCP server (that's where I get this idea). So, I'm a little dissoriented on where to investigate to complete the task, my question is:
How Can I make , programaticaly, my mock applications to get its own IP addresses via DHCP?
(or, Is it impossible, given the .NET Framework?)
Haj.-
You can certainly talk to the DHCP server -- the packet format is documented in RFC 2131. Doing this from C# is relatively simple.
However, all this does is "steal" an IP address from the DHCP server's pool. It doesn't actually bind it to the network stack.
It sounds like you still need to get your application to listen on this IP address. Unless this IP address is assigned to the network adapter on the machine, this won't work.
In short: you need multiple network adapters, or a multi-homed network adapter. In which case, you'd be better off letting it sort itself out with DHCP.
On the other hand, if all of your traffic is local, install the "Microsoft Loopback Adapter", and assign a bunch of IP addresses to that.
You will certainly be able to do this in C#, but I doubt that there is an existing class for doing this (its not a normal thing to do!)
You will probably end up having to do it yourself by recieving / sending the packets yourself.
I managed to find the following link which might be useful:
http://social.msdn.microsoft.com/Forums/en-US/wsk/thread/836c2150-583c-43a6-93b3-0e3202c2e2f5
(I know it says creating a DHCP server, but it could be a good place to start in terms of looking up the DHCP protocol workings)
Having said that I suppose you might have some problems requesting a lease for an IP address from a different IP address.

Identify user and machine on the local network

In my company we use small application called IPMsg, a messenger kind of tool to pass messages and file to other fellows in company, even it allows to multicast the message.
And also it lists the user name, host name and IP addresses of users.
How can it do that? There is no server present for message routing and when checked through netstat command in CMD it does not show any details like what protocol and port it is using to communicate.
There is source code also available on the same site which is in VC++. I didn't understand a line of code... (I'm a C# guy)
Can anyone explain me how it can do that?
One simple way would be to let the application listen on a certain network port, and when you start your instance of it, it tries to connect to that port on each computer on the same network. If that other computer has that port open, and answers correctly, then you have found another instance of the application.
IPMsg probably multicasts a request for all clients to report their user and host details.
A similar mechanism is used when Windows Explorer attempts to find other machines on a network. A good description of this type of multicasting discovery is described here.
IPMsg is a daemon which listens to incoming connections on a specific port which is the connection port. You can find out which port it used by using Wireshark.
Start wireshark, start listening on the interface where you have connected to LAN and then start sending any message, wireshark will show you the message on the screen with the port number also.
The application is a peer-to-peer software and doesn't require a central server software to route messages. it only has a small daemon which accepts incoming connections. This is the way Jabber Instant messaging protocol also works.
As you said it lists username, hostname and ip address of users, do you mean it pings the network and finds it? If yes, then it is actually possible to find the IP addresses of computers on the Local Network which requires you to know the subnet on which you are connected.
You can use ARP/ICMP Ping to know the hosts present on your network provided you enter the correct subnet information
Multicasting a message is also nothing special. It is a feature provided with all Networking Stacks.
If you want mutlicasting in .NET, it is allowed. Check this page on Code Project which gives a nice example

Categories

Resources