Here's the question, I need to connect to a remote MySQL database from my C# Application, problem is the MySQL instance will block all access to all IP's apart from localhost, this can not be changed as its too much of a security issue.
The question is, is it possible to connect via a tunnel instead to a php script hosted on the server, this would then act as the mysql connection.
Any ideas and suggestions?
SQLYog (a mysql management GUI utility) already has this php tunnel script with its own custom API, so if you consider writing it yourself, would be nice to have cross-support. See Is there any good universal PHP MySQL HTTP tunnel?
yes, just create a simple PHP script that will give you the desired output and use http request from the c# application to that php script to get the data - basically, you'll be building a very simple REST API (with authentication)
p.s. I don't see how that would be more secure than SSH tunnelling
I ended up with going for an SSH port tunnel and achieving what I needed to do that way.
Related
My database is now hosted on a server which I only can reach using an SSH tunnel. My code uses NHibernate that worked before the move to the new server but afterwards I haven't been able to connect to the server.
Anyone have any example on how I can open an SSH tunnel and the create a session in NHibernate for the fetching and saving of data?
Update your connection string to target the local entrance to the SSH tunnel.
Update
It appears the question is really how to create an SSH tunnel from a .Net program. I'm not aware of any built-in functionality in .Net to do that. A quick google (https://www.google.co.uk/search?q=ssh+c%23) turned up some possibilities), here's one of them: https://sshnet.codeplex.com/
There appears to be several other libraries judging from the google results. Have you tried any of these?
I suspect it might also be possible to have your program start e.g. PuTTY with suitable command line arguments. I haven't researched this and a library would be cleaner of course.
Actually I'm using node.js and socket.io to establish a socket connection. For some reasons I need to replace the server part with an ASP.NET application. Therefore I have to replace the existing socket.IO-server with a suitable .NET pendant.
From my understanding socket.IO as well as SignalR use websockets. So can I replace the socket.io-server with a signalR-server without or with even minimal changes in the clients?
Actually I tried to setup a SignalR-Server using the following example http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-server
I'm able to connect to the hub when I use the sample code mentioned there.
But I'm not able to connect to this server using socket.IO or websockets in nodeJS. Maybe because of the magic with the hubs.
So is there any solution for an easy to use .NET package, hosted in IIS, that allows secured websocket-connections or secure tcp-socket connections between clients and my server. This solution should be quite standard so I can use Java or Node or anything else on client side?
I am working on an C# application which would use the remote MySQL database located in my website hosted on a Linux server with PHP & MySQL support.
I tried to connect directly to the MySQL database, but was not able to connect due to restrictions at my hoster side.
can somebody help me please, can i do that with this restrictions ?
You need access to port 3306 on the remote machine. You can test if you have access to this port using telnet or similar
telnet ip 3306
These are the solutions you have:
A) Create local dev environment: You don't provide much information. If my guess is correct you are developing locally and later you plan to deploy your c# application to web server, that also will contain mysql db.
Install mysql in your local machine
Get a copy of the DB.
Configure your C# program to connect to your local mysql (localhost:3306)
When you deploy code it to your web server, it will connect also to your "localhost 3306" that will be the mysql installed into the web server.
B) Use VPN to access mysql: If A is not applicable another solution consist in installing some kind of VPN between web server containing mySQL and the pc running your application. Once VPN is setup and you can access port 3306 (by telnet as explained before), then your app will work.
C) Open ports to access mysql: The most easy solution is asking for administrator to open ports for you. 99% of the times the answer will be no, so I will not follow this route. (Maybe there is some kind of solution in your web provider that allows to open specific ports for a given IP, but I doubt it)
You can't. The server needs to have allowed remote connections and if this isn't possible, than you're out of your luck.
But, there may be another way... If you can create a web service on the server you're able to connect from, you should be able to communicate with the data in mysql virtually from anywhere.
You can try to create a way of API, if your server blocks incoming connections from web, just overload MySQL Functions you need to use with PHP and "echo" results as a server, parse them as a client with your c# application, it is the only way to organize such a system, or, you can allow incoming connection to MySQL, then watch on this article on CodeProject
I am just learning c#, and am programming a Windows client that collects temperature data from the computer and needs to send it to a remote linux mySQL Database.
I was going to program it directly in the c# client, but I want to learn more ways to do this and gain experience. And programming it directly would be less secure and most likely require an extra connector.
Can any of you advise me of other ways, or ways you would do this?
Any way to program a C# program that acts as a web-service on my linux mySQL Server? Where should I look/search to learn more about this. Is it called something special? Or maybe its not done in C#?
Should I program a php script that accepts HTTP SEND/GET requests from my C# Desktop client?
Any other way?
What way is most 'professional' in the real world? Trying to learn on my own! :D
FORMAT:
Windows Desktop: client programmed in C# That retrieves temp data and needs to send to server
Linux Server: Runs Apache and mySQL Server with a database already setup. Closed to outside Connections
My advice is to set up a web service to communicate with your windows client. Directly connecting to mysql server is ok if they both resident in a same lan, but if not, for example your windows client is running on some laptop travelling everywhere or even the mysql server permits local incoming connection only, your should set up a web service. Also the http connection can usually go through firewalls while connections over other ports are blocked.
php is a good way to do this. Since you are learning c#, you may want to use c# to do the server side programming as well, so why not give a try of mono?
Directly exposing a MySQL Server to the internet is strongly dicouraged, Additionally this gives you a rather coarse-grained set of access rights, that might not be enough for your application, so running some sort of server app is the right way to go.
With mono you can run a lot of .Net (and thus C#) based code on a Linux server just fine. Rule of thumb is: If it doesn't have a Winforms GUI and no P/Invoke it will work just fine. Ofcourse this needs mono on the server, which is not given on most commercial hosts.
Running the server in PHP makes it a lot more portable, but has a performance overhead. Additionally it doesn't allow for some of your busines logic objects to be implemented in a DLL assembly and used on both sides.
As for the protocol: Chose your poison. Rule of thumb again is, that predefined protocols such as SOAP tend to need a bit more work (and more learning in the first go), but on the long term tend to be more robust.
For your special use-case I'd personally go with a quick PHP based solution where the protocol is just a simple GET with a few parameters, one being the temperature(s) and the others authenticating the client.
If the temperature sensor generates events, then I would 'push' the data from the Windows box to the Linux box - this will save the latter checking often and finding no updates. However if you are just taking temperature samples, I would 'pull' the data from the Linux machine. Either way, if you want to use HTTP you will need a web service on either side.
Alternatively, you could just connect to your MySQL database remotely from C#, and write the data directly (no web service would then be required). That might be the quickest way to get this working.
The 'which is professional' question is subjective - all three options above are fine. Just make the code clear and concise :)
For school I need to make a C# application which uses a MySQL database as backend. The only thing which is stopping me from doing that is the big firewall of our school blocking everything except HTTP traffic on Port 80.
Hosting the MySQL database on port 80 is not an option, because that's still no HTTP traffic.
Does anyone know a way in which I can still connect to the server?
You could just install a MySQL server locally and use the loopback address, in that way you don't need to access an external server.
I like using wamp, it's an Apache, PHP, MySQL server all in one.
Create a web service which will be accessed via port 80 and use that web service to access database.