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

标签 c# mysql database

嘿!

我刚刚创建了一个小的 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/

相关文章:

c# - LINQ to SQL - 使用部分类和方法扩展数据上下文时出现编译错误

php - 预订查询不考虑到达和出发日期

MySQL用父ID替换父名称

mysql - 如何对 MySql 表进行分区以使用 90 天旋转分区?

mysql - 从联接表中选择具有多次出现的列值的行

database - oracle如何在内存中保存一个表?

c# - NUnit CollectionAssert.AreEqual(expected,actual) vs Assert.IsTrue(expected.SequenceEqual(actual))

c# - 欧盟通用数据保护条例 (GDPR) 的 Cookie 建议(想法)

c# - 在 C# 中断言权限

python - 使用 SQLite 和 Python 读取数据库 : Incorrect number of binding supplied