MohammadReza Vahedi
MohammadReza Vahedi

Reputation: 729

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.

Upvotes: 2

Views: 4954

Answers (2)

Bob Vale
Bob Vale

Reputation: 18474

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

Upvotes: 2

rgrano
rgrano

Reputation: 351

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.

Upvotes: 0

Related Questions