i can't access to mysql database from c#

老子叫甜甜 提交于 2019-12-11 01:48:42

问题


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.


回答1:


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:


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.



来源:https://stackoverflow.com/questions/17474632/i-cant-access-to-mysql-database-from-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!