使用C#代码的用户拒绝远程MySql访问,但可以与DbVisualizer连接 [英] Remote MySql Access denied for user with C# code but can connect with DbVisualizer

查看:152
本文介绍了使用C#代码的用户拒绝远程MySql访问,但可以与DbVisualizer连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在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.

推荐答案

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

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();
}

这篇关于使用C#代码的用户拒绝远程MySql访问,但可以与DbVisualizer连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆