使用 C# 代码的用户拒绝远程 MySql 访问,但可以使用 DbVisualizer 连接

发布于 2024-10-18 03:16:47 字数 167 浏览 5 评论 0原文

我可以在 C#/.Net winform 应用程序中连接到本地 MySql 服务器,但是当我尝试连接到远程 MySql 服务器时。我收到“用户 @'%' 访问数据库被拒绝”错误消息。但是,如果远程服务器拒绝连接。为什么我可以用DbVisualizer连接到远程MySql数据库?我很确定问题不在于代码,而在于服务器设置。

I can connect to local MySql server in my C#/.Net winform app but when I try to connect to a remote MySql server. I got a "Access denied for user @'%' to database" error message. However, if the remote server is denying the connection. How come I can connect to the remote MySql database with DbVisualizer? I'm pretty sure the problem is not with code but rather the server settings.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尘曦 2024-10-25 03:16:47

我在使用 Java 时也遇到了同样的问题。我的问题的解决方案是不指定目录。不知道C#是不是这样,你试试吧。

I had the same problem with Java. Solution to my problem was not specifying the catalog. I'm not sure if this is the case with C#, give it a try.

傾旎 2024-10-25 03:16:47

将此代码与您的进行比较。

private void button1_Click(object sender, System.EventArgs e)
{
        string MyConString = "SERVER=localhost;" +
            "DATABASE=mydatabase;" +
            "UID=testuser;" +
            "PASSWORD=testpassword;";
        MySqlConnection connection = new MySqlConnection(MyConString);
        MySqlCommand command = connection.CreateCommand();
        MySqlDataReader Reader;
        command.CommandText = "select * from mycustomers";
        connection.Open();
        Reader = command.ExecuteReader();
        while (Reader.Read())
        {
            string thisrow = "";
            for (int i= 0;i<Reader.FieldCount;i++)
                    thisrow+=Reader.GetValue(i).ToString() + ",";
            listBox1.Items.Add(thisrow);
        }
        connection.Close();
}

compare this code with yours.

private void button1_Click(object sender, System.EventArgs e)
{
        string MyConString = "SERVER=localhost;" +
            "DATABASE=mydatabase;" +
            "UID=testuser;" +
            "PASSWORD=testpassword;";
        MySqlConnection connection = new MySqlConnection(MyConString);
        MySqlCommand command = connection.CreateCommand();
        MySqlDataReader Reader;
        command.CommandText = "select * from mycustomers";
        connection.Open();
        Reader = command.ExecuteReader();
        while (Reader.Read())
        {
            string thisrow = "";
            for (int i= 0;i<Reader.FieldCount;i++)
                    thisrow+=Reader.GetValue(i).ToString() + ",";
            listBox1.Items.Add(thisrow);
        }
        connection.Close();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文