Unable to connect to MySQL from C#
update: I have connect my provider and it turns 开发者_如何转开发out that servers are blocked firewall, we can only use a php connection string script like this
$db=mysql_connect("yourdomain.com.mysql", "username", "password"); mysql_select_db("database", $db);
is there anyway i can connect the database now? with a c# form application
Im unable to connect to mysql, I get error 1042 using MySql.Data.dll version 6.4
this is which I use to connect to server
string myConnectionString = "server=mydata_net;uid=mydata_net;pwd=test21;database=myweb.net;";
try
{
MySqlConnection conn = new MySqlConnection(myConnectionString);
conn.Open();
MessageBox.Show("OK");
conn.Close();
}
catch (MySqlException ex)
{
switch (ex.Number)
{
case 0:
MessageBox.Show("Cannot connect to server. Contact administrator");
break;
case 1042:
MessageBox.Show("Can't get hostname address");
break;
case 1045:
MessageBox.Show("Invalid username/password");
break;
}
}
Make sure you change 'mydata_net' to 'myweb.net' at the 'myConnectionString' and you'll be fine.
It's a simple typo.
Edit:
myConnectionString = "server=mydata_net;uid=mydata_net;" +
"pwd=test21;database=myweb_net;";
should become
myConnectionString = "server=myweb.net;uid=mydata_net;" +
"pwd=test21;database=myweb_net;";
精彩评论