2011-09-05 56 views
1

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

我刚刚创建了一个小小的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工作台从远程I可以normaly登录

请帮忙

+2

'SERVER = http:// xxx',http是必要的吗? – ajreal

+0

你是对的,现在它的工作,发布它作为答案,我会打勾它 – test123123

+0

超过必要的是它甚至有效,我怀疑应该只是一个domnain名称或ip“http://”是什么导致问题。 –

回答

3

SERVER=http://xxx在这种情况下数据库连接不需要http://的预先准备。

相关问题