无法连接到任何指定的MySQL主机

时间:2011-09-05 12:47:30

标签: c# mysql database

HY!

我刚刚创建了一个小的MYSQL远程c#工具。

问题是,我收到错误:无法连接到任何指定的MySQL主机

CODE:

string myConnectionString = "SERVER=http://xxx;PORT=3306;" +
                            "DATABASE=xxx;" +
                            "UID=root;" +
                            "PASSWORD=xxx;";

            MySqlConnection connection = new MySqlConnection(myConnectionString);
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "SELECT * FROM USER";
            MySqlDataReader Reader;
            connection.Open();//Here ocurres the error
            Reader = command.ExecuteReader();
            string tmp ="";
            while (Reader.Read())
            {
                string row = "";
                for (int i = 0; i < Reader.FieldCount; i++)
                    row += Reader.GetValue(i).ToString() + ", ";
                tmp += row + "\n";
            }
            MessageBox.Show(tmp);

            connection.Close();

当我从远程使用MYSQL Workbench时,我可以正常登录

请帮忙

1 个答案:

答案 0 :(得分:3)

SERVER=http://xxx在这种情况下,数据库连接不需要http://的预挂起。