C# - Remote Connection to XAMPP-Database via LAN - c#

I have a database hosted with XAMPP on a PC with IP: 10.35.250.195
I want to access this database from a laptop in the same LAN where my C#-Application is running on.
This is my connection-string:
"SERVER=10.35.250.195;DATABASE=testdb;USERID=root;PASSWORD=;"
But I'm being unable to open a connection from a remote pc/laptop.
I can access the database with the above connection-string from the PC where the database is hosted. I can also access the phpmyadmin in the browser from the remote laptop with "10.35.250.195/phpmyadmin". So the connection works from the laptop to the PC with the database, but I am not able to open this remote connection in C#.
Within phpmyadmin I allowed user "root" to access host 10.35.250.195 with all rights and I even allowed that every user can access host 10.35.250.195 with all rights to get sure (I know I should not do this because of security reasons...).
How can I access the database in c# with mysql from a remote PC via Lan? Can somebody help me to find the fault?

Maybe your port of the DB is blocked by a firewall?
MySql has Port: 3306
and you could also try a PC based tool to test it like
https://www.heidisql.com/

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.

How to connect to Remote Mysql server that requires SSH?

Not sure this is the place to ask this, but I am trying to connect to a server which I have full access to. I can login to the phpMyAdmin from the web, but when I try to connect to it from C#, it doesn't work. It shows the following error in particular:
Unable to connect to any of the specified mysql hosts
Here's the connection string I'm using:
string mycon = "server=someIP;port=3306;uid=user;pwd=pwd;database=mydb;Convert Zero Datetime=True";
I think this is because the server requires SSH. Is there any way I can disable SSH requirement for the connection?
If port 3306 is closed, you won't be able to connect from a remote host. PHPmyadmin works because it is running on the same machine as the mysql server (I assume) so it is not connecting from a remote host. You need to either open port 3306 and configure mysql to listen to port 3306, or you mention that you have ssh, which opens up another option.
If you aren't able to open 3306 to the general public, you could create an ssh tunnel to the server that forwards 3306 on the mysql server to some port on your local machine (like 3307), then configure C# to connect to that local port.
string mycon = "server=localhost;port=3307;uid=user;pwd=pwd;database=mydb;Convert Zero Datetime=True";
Here's an example of how to forward a port with putty.
http://www.cs.uu.nl/technical/services/ssh/putty/puttyfw.html
Also, the easiest way to check for open ports on an ip is a port scanner like nmap. I'm assuming you're on windows since you're using C#.
There is windows gui client here: http://nmap.org/zenmap/
I finally solved the problem by changing the mysql configuration in my.cnf
It was previously:
bind-address = 127.0.0.1
and I changed it to
bind-address = 0.0.0.0
Restart mysql service, and everything's fine :)

i can't access to mysql database from c#

i have a web site and in it's phpmyadmin create a database and i want to connect to it from c#.
i use MySQL connector for .NET in visual studio 2010.
my String Connection is :
server=158.58.185.197;database=porbarco_base;uid=****;pwd=****;CharSet=utf8;
but i can't connect to database and give an error : Unable to connect to any of the specified MySQL hosts.
How i can connect to this database.
i see many threads in stackoverflow but don't solve my problem.
The likelyhood is that the problem is less your C# and more remote access to MySQL
You need to check the following.
Is MySQL listening a network address. Check your mysql configuration file. Look for an entry for bind address. if its set to 127.0.0.1 then you are just listening on localhost, change it to 0.0.0.0 and remember to restart the service
Is your linux firewall blocking remote access to the mysql port.
Does your mysql allow remote access for the specified user from a remote host. see This link for an example of how to set this up
If you are trying to access it directly using the IP address then the port 3306 needs to be open. Is the port open? If the application is hosted on the same server as the database then I would recommend using localhost to access it instead of the IP address.

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)

winform(C#) connect remote oracle database

I meet a problem in developing winform (C#) project.
How can the client from one computer of the local network A connect the oracle database which is in one computer of network B (A and B are not in the same local network).
Possible solutions :
Setting up a vpn to access the network where the Oracle database is hosted.
Setting up ssh (similar to vpn) (http://www.akadia.com/services/ssh_connect_tunnels.html)
Directly expose the server and port Oracle is running on to the internet, you'll need a static ip for this to work (not recommended).
Setting up a connection manager on a dmz server

Categories

Resources