kalenderdose
kalenderdose

Reputation: 69

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.

Upvotes: 0

Views: 399

Answers (2)

Saman Gholami
Saman Gholami

Reputation: 3512

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.

Upvotes: 1

Bernhard Hiller
Bernhard Hiller

Reputation: 2397

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.

Upvotes: 1

Related Questions