简体   繁体   中英

mysql c# unable to connect to host (0x800004005)

i've got a problem. I cannot connect to a mysql database. This is my errormessage:

MySql.Data.MySqlClient.MySqlException(0x80004005): Unable to connect to any of the specifed MySQL hosts.

The i think its an misstake in this lines. I cann connect form another extern server via C (same user) to the database.

MySqlConnection mdcon;
try
{
    string myConnectionString = String.Format("SERVER={0}; " +
                    "DATABASE={1}; " +
                    "UID={2}; " +
                    "port={3}; " +
                    "PASSWORD={4};", textBox_MD_IP.Text, textBox_MD_dbname.Text, textBox_MD_user.Text, textBox_MD_Port.Text, textBox_MD_pass.Text);
    MessageBox.Show(myConnectionString);
    mdcon = new MySqlConnection(myConnectionString);
    mdcon.Open();
    MessageBox.Show("Verbindung erfolgreich!");
    mdcon.Close();
}
catch (Exception msg)
{
    MessageBox.Show(msg.ToString());  
    throw;
}

I would be very happy if somebody can help me.

MySQL Server can be configured to allow for conenctions from localhost only, from localhost and specified other computers, or from any computer. Hence check the configuration of the server. Also, check firewall settings of your local computer.

string myConnectionString = String.Format("SERVER={0};" +
                    "DATABASE={1};" +
                    "UID={2};" +
                    "port={3};" +
                    "PASSWORD={4};", textBox_MD_IP.Text, textBox_MD_dbname.Text, textBox_MD_user.Text, textBox_MD_Port.Text, textBox_MD_pass.Text);

I think shouldn't use white-spaces in the connection string. So change "DATABASE={1}; " to "DATABASE={1};" and etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM