嘿!
我刚刚创建了一个小的 MYSQL 远程 c# 工具。
问题是,我收到错误:无法连接到任何指定的 MySQL 主机
代码:
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 时,我可以正常登录
请帮忙
最佳答案
SERVER=http://xxx
在这种情况下,数据库连接不需要http://
的前缀。
关于c# - 无法连接到任何指定的 MySQL 主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7308314/