How do i connect to a remote mysql server in .NET?
I am using ubuntu in VMWare. I installed mysql and have it running. I can login with the user root and a password. I have the IP of the VM box. In my code i wrote
using MySql.Data; return new MySql.D开发者_JS百科ata.MySqlClient.MySqlConnection("username=root;data source=192.168.100.129,password=xyz");
instead of data source i also tried server. I get the exception message Unable to connect to any of the specified MySQL hosts.
i ran netstat -an | grep -i mysql
and saw
unix 2 [ ACC ] STREAM LISTENING 23404 /var/run/mysqld/mysqld.sock
so i added port=23404; and tried both data source
and server
. No luck. I can indeed ping that address on the virtual machine (i got the address using ifconfig). So Whats my problem and how do i connect? This is the first time i am using this. I always used sqlite in the past.
Sounds like a MySQL problem rather than a .NET problem. By default MySQL only listens for connections from localhost (for security reasons). You need to explicitly tell it not to do so. See this: http://www.howtogeek.com/howto/mysql/switch-mysql-to-listen-on-tcp/ .
精彩评论