2

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.

3
  • Can you connect to the database at all from that machine using the given information?
    – Paul
    Jul 4, 2013 at 16:18
  • 1
    So can you connect to it as that user from that machine outside of your code? Jul 4, 2013 at 16:18
  • i can connect to database in my php code as localhost. i can connect to localhost mysql in my pc in C# Jul 4, 2013 at 16:21

2 Answers 2

2

The likelyhood is that the problem is less your C# and more remote access to MySQL

You need to check the following.

  1. 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

  2. Is your linux firewall blocking remote access to the mysql port.

  3. 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

2
  • 1
    i don't access to mysql configuration files and linux firewall. i have an account in the site navidiranian.ir and use direct admin to administrate database and domain and so on. i found my problem and Explain it in below answer. Jul 4, 2013 at 20:11
  • 1
    @MohammadRezaVahedi Your comment doesn't make sense. Name resolution will have nothing to do with it, you are using the ip address directly. It is not that. The likelihood is that your host provider doesn't support remote access to the MySQL database, which is not surprising as this is a big security hole. A quick look with nmap shows that port 3306 is not open on that server.
    – Bob Vale
    Jul 4, 2013 at 22:06
0

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.

7
  • port 3306 is open. my application is C# and server is linux base. i want to remotely access to database. Jul 4, 2013 at 16:37
  • Try specifying the port right in the connection string as follows: Server=158.58.185.197;Port=3306;
    – rgrano
    Jul 4, 2013 at 16:41
  • Is it case sensitive? Try this version: Server=158.58.185.197;Port=3306;Database=porbarco_base;Uid=myUsername;Pwd=myPassword;CharSet=utf8;
    – rgrano
    Jul 4, 2013 at 16:57
  • I do this and no change in Result. Jul 4, 2013 at 17:02
  • Is your issue at all related to this posting: stackoverflow.com/questions/5915534/…
    – rgrano
    Jul 4, 2013 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.