How to connect MySQL running on a web server from c#? - c#

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

Related

can't connect to a database remotely on a c# app which i can see by visiting that server's phpmyadmin site

I have added a database via phpmyadmin on a server. I can access it via http://ipaddress/phpmyadmin . but when i try using those credentials to connect to that db on a c# app , i get the error : unable to retrieve the list of database.
I don't have the right to access the server. I have a user who has rights to two db which i can see when i remotely connect to that server's phpmyadmin. Is it possible that i have right to the db just via phpmyadmin but can't access it via app because i don't have the right to do it because mysql is forbidding it ? I also have a raspberry pi handy. is using it as a db server a better alternative than this ?
Since phpMyAdmin runs on a web server, most people install it on the same machine the database is running on and access it remotely through the network. That means their phpMyAdmin is communicating with MySQL locally, often without the connection leaving the server. Your C# application, on the other hand, is a compiled application that would likely run on your client machine, not the server - meaning any connection from the application to the database is occurring through the network (or internet, depending again on your configuration). Since exposing the MySQL port is generally a bad idea, your MySQL may be configured to only listen locally, or you may have a firewall or NAT connection blocking you from even reaching the server. If that's the case, you may need to rethink how you'll communicate with the database (oftentimes exposing an API is a better solution than opening port 3306 to the world).
It's also possible you're using two different user accounts. To MySQL, an individual user account consists not only of the username, but also the hostname. You can use a wildcard hostname (%) which means all hosts, except it's really "all hosts connecting via TCP/IP networking connection."
It's possible that your application and your phpMyAdmin are using two different connection methods; one using TCP/IP and the other using sockets. Check which phpMyAdmin is using (the easiest way to do so is to look at the host phpMyAdmin is connecting to; 'localhost' is a socket connection and '127.0.0.1' is networking). Configure your C# application the same way.

mysql remote server access from C# application

I have done a small C# Win Forms application, that connects to mySQL database using mySQLconnector. This works perfectly ok with my localhost.
String ConnectionString = "server=xx.xxx.xx.xxx;uid=myuserid;pwd=mypassword;database=dbname";
But I do get following error when I try to connect to remote server:
Unable to connect to any of the specified MySQL hosts.
{"No connection could be made because the target machine actively refused it xx.xxx.xx.xxx:3306"}
I have pinged the server from command prompt and I get response.
I also verified mySQL server settings in remote server database (correct name/ip, portno:3306, skip networking:OFF)
The remote server is accessible without any problem from web server that runs php script and uses same settings as the connection sting I listed above.
The mySQL server is hosted on external shared hosting company 123reg.co.uk with me logging to phpmyadmin using same uid/passwd as like in connection string.
I can't understand what is different between webserver accessing OK, but my C# app having trouble with it??
Can any one please help...
Thanks in Advance
Sam
I've had issues with servers setup so they won't accept remote connections. This is for security reasons mainly. Some places will let you enable it in the CP, but if you have direct access to the server, you should be able to follow these steps.
http://www.rackspace.com/knowledge_center/article/mysql-connect-to-your-database-remotely
Your ip address will be different from the web server.
If your ip address is static you can grant access to your ip address within your mysql database ( https://www.google.com.au/search?q=mysql+grant+access+to+user+from+host ).
I'd recommend using the server to access the database and make your c# application talk to your webserver using ajax/json calls ( https://www.google.com.au/search?q=C%23+Win+Forms+ajax+json ) - that way you're not tied to an ip address for access.
Alternatively you can look at setting up ssh tunnels to your webserver if remote shell access is available so you can get the same access as your webserver. ( https://www.google.com.au/search?q=ssh+tunnels+example+mysql That's what I do myself)

Connect ASP.Net application from web to my sql database on my computer

I am creating two applications: An ASP.Net application and a C# application. I used SQL Server as the database. My ASP.Net application should connect to the internet but the database should only be on my computer. I used connectionString to connect my two applications in just one database (SQL). Is there a way to connect my ASP.Net application from the web to my SQL database on my computer?
I've read lots of tutorial but I can't find the solution.
Ordinary SQL Server is local to to the Web application (it's either located on the same LAN or sometimes even on the same machine).
Technically it is possible to connect an ASP.NET application to a remote SQL server, but it is not recommended, you can open a can of worms there (problems with firewalls, ports, performance etc.)
Here's my solution for that:
Make sure you have a static IP address assigned by the ISP.
Make sure that you assign a static IP address in your computer.
Now, use "Port Forwarding" technique. Configure your router to forward the packets from port 1433 going to your computer.
The next thing you do is you configure or modify your web.config (ASP.NET file) that is deployed outside your network (in a hosting company) and make sure that the datasource of your connectionString looks something like this: connectionString="data source=214.23.12.21 (where 214.23.12.21 is the static public IP assigned to you by your ISP).

How can I connect to MySQL from behind a firewall?

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.

Oracle remote connection without installing the oracle client

Is there a way to connect to a remote oracle DB from a client PC without installing oracle on the client ?
You need to download an ADO.NET driver for Oracle. Here's a step by step guide.
You don't need to install all of Oracle but only the ODBC driver.
Everything depends upon the remote server. If the remote server is not permitting remote access to db then u cannot access it anyway.Instead u need to build some sort of webservice and deploy that web service to the same remote server. And call the web service into your app.
The web service will act as a local app to db and will return your desired things, written in code. If its allowing remote access then as adviced above are good options.
I hope, you got it.

Categories

Resources