I have a windows form application in C# and sometimes I want to push some data table from this application to an online mySql
server which is hosting all data for my website in PHP
. To do that I've installed :
1- MySql
for visual studio version 1.2.3
2- MySql
Connector.Net 6.9
Also, I have enabled Remote MySql
on the server so I can make the connection. I used the '%' wildcard for the meantime because my IP address is dynamic.
my basic c# connection code is as below :
MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;
myConnectionString = "Server=*******;Database=*******;Uid=******;Pwd=********;";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection();
conn.ConnectionString = myConnectionString;
conn.Open();
MessageBox.Show("connected successfully..");
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message);
}
Unfortunately, every time I run this code I am getting an error which says "Unable to connect to any of the specified MySQL
hosts". I don't' know where the problem is. Is it something on the UNIX server which blocks the connections or some other thing which I need to do. I am also new to the CPanel interface and how to deal with it.
I appreciate all the help provided. Many Thanks.
http://www.codeproject.com/Articles/43438/Connect-C-to-MySQL
Did you see that? You can try it.
I know this is an old question but I had the same issue many years ago and the only way I could get it to work was to enable remote MySql on the server I was running. This basically means allowing remote connections to access the DB. This of course is very risky and poses a major security problem. You can limit connections from specific IPs, but in my opinion its best to have a local DB and then perhaps push updates to an online source somehow.