How to connect my .net application to SQL Server via internet - c#

I have created a C# application with a login form (I use SQL Server database and SSMS). The database is on my PC, when I run the program on another PC which is in the same network as mine, everything works fine, but when I connect one of the laptops on another network, an error occurs: "The path wasn't found".
Is it possible to connect with the server remotely, via internet or something,
without having to be on the same network?
I already have:
Opened tcp and udp ports
Allowed SQL Server ports in Windows Firewall
Added an inbound rule for tcp (port 1433) and udp (port 1434)
Allowed remote connections
Here is my connection string:
Data Source=<server name>;Initial Catalog=Name;User ID=Minko;Password=Password1

This is not a programming question, but a Networking one.
To have a server reachable in the internet, is a costly mater. The static IP adress alone will cost a pretty penny, never mind actuall hardware.
On a small/no budget, VPN is perhaps the only way. Via VPN you can connect two local Networks (the home side of the Routers), allowing devices to talk as if they were physically in the same network.
No change to the programm is nessesary. If it works local, it works over VPN. The network classes do not care if the target is on the same computer, the same Switch or the Voyager probes.
The user will have to connect to teh VPN endpoint you have to provide - and usually can provide for cheap with any decent Router.

First off you should definitely change that PW.
Also - you make the comment that you are trying to use the same program to connect from a different network - implying that you haven't changed the IP address...
Are you sure you're using your public IP address? (Not your local network one that will start with 10. / 172. / 192.
Make sure you're using your public IP address... if you do this even if you're on the same network it will treat it as if you're not. It seems to me like you're still trying to use the local network's IP.
If it persists make sure you can reach the PC itself: ping ip-of-host in Powershell.
Connecting C# with SQL Server Database in a Local Area Network (LAN)

Try these steps one by one :
1- Find your public IP address using ( www.whatismyip.com ) for example.
2- Check that you can connect to the database using the public IP. To do that go to SSMS, and in the server name try to use IP-address only, or "IP-address\[instance-name]. If doesn't work, then you have to fix this first. Check this: https://dba.stackexchange.com/questions/62165/i-cant-connect-to-my-servers-sql-database-via-an-ip-address
3- When step 2 works, then you can use the "IP-Address\[instance-name]" in the connection string.

Related

Host server on Raspberry

Ive made a simple chat Program in c#. It uses tcp. I can start the server and clients can connect and chat if everyone is in the same network.
I now want to put the server on my raspberry pi which has raspbian installed.
So far so good it works and i can connect again if everyone is in the same network, but now i want to access the server over the internet as a private person cant geht their hands on an public static ip adress, ive read that i could use ddns.
I have a host name on no-ip and installed noip2 on the raspberry and followed the instructions.
On their site they write you can test it with the command sudo noip2 -S. It shows that it connected with my account and will update my hostname.
In theory everything should be working, but i cannot connect to the server neither to the raspberry.
Anyone of you knows what i can do to make it work or is it the completely wrong way?
Thanks in advance!
You could use dyndns together with cname.
You would need to open port 80, 443 on your router.
This implies risk for the other devices in your network.
Instead of using rpi locally you could get a small virtual hosting server at AWS/Google for around 3$ per month.
Simply put, if you don't have a public IP, there's no way to connect to your RPi. If the IP address starts with 192.168, 172.16 through 32 or 10. then it's by convention (or definition depending on how you look at it) a non-routable address which means you can't get to it over the Internet.
DDNS is just a way of translating from a name to an IP address and doesn't imply anything about being accessible to the public. Noip is just a way of being able to associate a name with a dynamic IP address, which again does not imply anything about being accessible to the public. In other words, if www.yourdomain.com resolves to 192.168.1.2 (for example), it doesn't matter who can resolve the name, they still can't get to your server.
If your router has a public IP (which you said it doesn't) then you would be able to do a NAT translation, but based on what you said, that's not possible either.

How to handle any request coming to my virtual wifi hotspot in Windows 7

I want to take control over all the requests which arrive to the virtual wifi hotspot.
I opened up a wifi hotspot via Microsoft Virtual WiFi Mini Adaptor through command prompt. I used netsh wlan start hostednetwork. I also put it into static ip mode to overcome with the android stuck at obtaining ip address issue. Everything is working fine.
Some time ago I built a server software with C# which binds to internal ip address of the wifi hotspot. I use it as a file server, remote computer controlling purposes.
Here is core section: If you connect to the hotspot from a device like android phone or pc, open the browser and type http://192.168.137.1:8080/ (hotspot pc ip address) on address bar, you simply connect to it and a home page appears and so on. But I want every client to be redirected to my server.
So regardless of what they put into address bar like google.com, facebook, yahoo, they will be redirected to my server and visit its homepage. This is something like controlling DNS, I guess. Is it possible to take control over every request that way?
I finally figured it out. First of all I need a DHCP server.
Here is one: http://tftpd32.jounin.net/
This also may help: http://www.wikihow.com/Set-up-DHCP-on-a-Local-Area-Network
With this program I can run and configure its DHCP server. I need to set the DNS server address to my own servers address (like 192.168.0.1 which is default gateway). So when clients connect to my virtual hotspot, they will receive this as a DNS server address. Clients will request every domain name from that address (instead of 8.8.8.8 which is Google Public DNS for example). So I also need a DNS server of my own. It must be bound to port 53 (192.168.0.1:53 with UDP protocol, not TCP!!) which is default DNS port number. Main server must be bound to 192.168.0.1:80 with TCP. Notice that it is bound to HTTP port.
If everything goes fine after doing these, my DNS server will give main servers IP address to clients regardless of the domain name IP they requested. Hence they will connect to my server instead of real ones (facebook,youtube etc).
By the way the DHCP server program which I given the url of is working very well for me. It is very simple and efficient. It will eliminate issues like "Android stuck at obtaining IP address". It also provides other servers such as TFTP, SNTP, SysLog and DNS. It also works so fine even without any advanced virtual hotspot program (such as Connectify). You may only call "netsh wlan start hostednetwork" command. I don't intent any promotion here. I'm just trying to help.
If you want redirecting all domain search queries to your ip address you have to control the DNS.
The best way is to operate as a proxy service between your client and the destination, so you can manipulate the query of the client.

using a server to manage tcp connections

I have a server application and a client application in order to send and receive files between computers.
you may skip this part:
My algorithm is as follows:
`server: start listening for connections
client: establish a connection with the server
server: start a thread where that thread consist of a method listening for data send through the network stream
client: also start listening for data on a while loop runing on a separate thread.
\\so far if the client sends a byte array through the connection netwrok stream the server will receive it.
\\ also in each while lop the client and server there is a switch statement. if data received commes with the string "<file>" then it will start listening for the transfer of a file
client: send the string "<file>" to the server and start listening for that file on a different method.
server: because it receives the "<file>" keword it exits the listening loop and sends "<ok>" reply
.... so the talking between server and client keeps going ...........`
also the server is running yet more other threads such as still listening for
new connections. maybe another client want's to connect to it. so every time
a client connects the server, the server will start doing the same process
again on a separate thread (listening for new connections).
So as you can see everything that get's sent through the network stream get's received by the other application.
So everything works great when a connection is established
Now think about the things that have to happen in order to establish a connection from computer A that happens to be in a house and Computer B happens to be on a office on a different network. Note (computer A and computer B have internet access). so let's say you want your computer A to be the server and computer B to be the client. So you will have to start the server. great the server is now running. Then you will start the client application. You will also have to tell the router in the house to forward all traffic from port X to that server computer so that computer B is able to find it. Once you do that computer B is able to establish a connection. If next day you have a different IP address because most of us we don't have static IP you will have to change that IP on the client computer in order to establish a connection. so it can get quite complicated and not friendly. Also you may want your office computer to be the server because it might always be on but maybe you don't have access to the router so you are screwed.
Solutions:
1)
on my house call my internet service providers and pay to get a static IP.
I have not developed an algorithm but basically now computer A and computer
B will be clients and they will be connected to my computer at my house.
(on my house I will have to configure the router obviously to do port forwarding).
so know if computer A wants to send a file to computer B the server at my house
needs to have those to connections. the connection between computer A and the
connection through computer B. If something get's sent to the server at my
house from computer A then sent that to computer B and vice versa.
problems with this solution is: The upload speed at my house is very slow therefore
the transferring of files will be slow. also I don't know if my network at my
house will be able to manage multiple connections.
2)
step 1)
Host a website from my home still getting a static ip address. this time I also
have to get a domain so that users can remember me. so let's say that I am able
to host this website hosted on my house as somedomain.com . soon you understand
the purpose of the website....
step 2)
I don't know that much about this it is called "UDP punch hole into firewall".
this basically tells the router to port forward all traffic from port x to the
server so that users don't have to open ports on their routers. I DO NOT KNOW
HOW TO DEVELOP THIS I HAVE JUST HEARD ABOUT IT. so if I develop this computer
A will be able to connect to computer B without having to do any configuration
on the router which is nice.
step 3)
let's say that computer B is the server and computer A is the client that want's
to connect to computer B. so computer B will talk to my website at my house and
tell it that it is listening for connections on the ip address xxx.xxx.xxx.xxx .
then the client computer will access the website at my house and see the ip address
of computer B. now the connection is going to be able to be established.
step 4)
If the internet IP address of computer B changes for example. then let my website
know the new IP address. next time the client want's to connect to the server it
will be able to find the correct IP by looking into my website.
problems with this technique: I do not know how to implement
"UDP punch hole into firewall" so that users do not have to do any configurations
on their routers. an example of this will be helpful.
3)
there are a lot of companies out there that can host you a website. I don't know
about a company that will let me run a c# console application on their server.
Also I don't know if the file transfer of data going from computer A to a server
then to Computer B is more efficient than data going from computer A to computer B.
This solution will enable me to stop thinking about users having to configure their
routers which is nice.
This application enables you to do many more things. I know there are several applications that will enable me to just transfer files. It will be nice if someone will point me on the right direction of which technique to use.
If you use a a free DNS provider like DynDns free and a DNS updater for your dynamic IP like this one, then you can connect to your server by DNS name instead of IP address. Using the updater, when your address changes, the DNS record will be updated at the DNS provider.
Another option might be to use DropBox to synchronize a folder between the client and the server, and then convert your server application into a directory monitor that looks for new files synchronized by dropbox.

Testing for network connectivity via opening a database connection

I have a little .net 2.0 systray app (C#) that checks for network connectivity periodically. It does this by attempting to open a connection to a SQL-Server instance on another computer (and selection a row from a table). The application saves documents created by another process to a database when it finds a connection. It is going to be used in environments with potentially dicey wireless networks.
In testing our QA team is using ipconfig /Release on the DB server (hosting a Sql-Server 2005 DB). What we found was that the application continued to claim it was network connected, because it kept right on successfully opening connections to SQL Server. I found the systray app's behavior erratic in my own testing using ipconfig /release.
At the suggestion of our not-currently-present network guy I changed my own internal testing (app hosted on a VM, connecting to DB on my workstation) to instead turn off the VM network connection. This produces the expected behavior (the systray app can't find a network connection). The QA guys are a little leery about my suggested that they do the same, and I need to put them at ease.
It was suggested to me that SQL Server was using named-pipes to accept incoming connections. If Named Pipes and TCP/IP are enabled, does this invalidate the ipconfig /release test?
I don't really know much about networking. Named-pipes, according to what I have read, sounds like it is designed for use between applications on the same server. But it can be used for intranet communications?
Is there something else going on here that I an unware of? Something about how ipconfig /release works
For your application, I would only use TCP/IP communication protocol. Although SQL Server supports other communication protocols such as named pipes, I would disable them on your server so it only accepts TCP/IP connections. This is least amount of overhead and should perform the best regardless of connection speed.
Named pipes is a different protocol then TCP/IP, so releasing the IP address may not effect named pipe communication in any way (Sounds like it is).
On the SQL Server machine, put TCP/IP as the number 1 protocol and disable named pipes. The have QA re-run the test. I have included a configuration screen shot for reference.

How to forward ports over an SSH tunnel using Granados with C#

I'm using the Granados SSH Library and I'm trying to forward port 3306 on my localhost to port 3306 on the remote host (i.e. the MySQL server port). That is, I want to be able to make connections to the remote host's MySQL server through the SSH tunnel.
Here is an example of what I've currently tried using the Granada .NET SSH library but which doesn't seem to work:
public SSHConnection _conn;
_conn.ListenForwardedPort("localhost", 3306); //doesn't work
Can somebody please tell me how I can achieve what I want?
You have your terminology backwards! What you are trying to do is tunnel from the local machine to the remote system. This is because the remote system is the TCP server so a connection is initiated on your local system and accepted on the remote system. The ListenForwardedPort method is for the other direction.
I didn't test this but from my read of the Granados source code I think you want the ForwardPort method instead. It takes four host-related arguments like this:
remote_host: the host with the server on it, i.e. your MySQL server
remote_port: the port the server is listening on, i.e. 3306
originator_host: the host you want to listen on the local side, probably "localhost"
originator_port: the port of the host you want to connect to on the local side, you can re-use 3306 or pick any other available number
Your MySQL server, the remote_host, might be "localhost" (as seen by the other endpoint of the SSH connection) but it could also be any machine reachable by the remote system. You can also use the IP address of the remote system, i.e. something other than localhost or 127.0.0.1.

Categories