从C#连接到MySQL [英] Connect to MySQL from c#

查看:108
本文介绍了从C#连接到MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PhpMyadmin位于https://178.250.xxx.xxx/myadmin

 私有 无效 button1_Click(对象发​​件人,EventArgs e)
        {
 
            服务器= " ;
            database = " ;
            uid = " ;
            密码= " ;
            字符串 connectionString;
            connectionString = "  +服务器+ " ;" +   DATABASE =" +
            数据库+ "  + "  UID =" + uid +  ;" + "  +密码+ " ;";
 
            connection =  MySQLConnection(connectionString);
            connection.Open(); // 显示错误
            MySQLCommand cmd;
            cmd = 新建 MySQLDriverCS.MySQLCommand(" ,连接);
            MessageBox.Show(cmd.CommandText);
            cmd.ExecuteNonQuery();
           
        } 


 MySQLDriverCS异常:MySQLDriverCS错误:无法连接.无法连接到'localhost'(10061)上的MySQL服务器

解决方案

我看到的唯一可能的错误可能是您的服务器字符串.
只需将ip传递到没有路径的连接即可.
如果您的服务器没有监听默认端口(3306),则还应指定它(Port = xyz;)

最好的问候


使用以下命令重新检查连接字符串: http://www.connectionstrings.com/mysql [^ ]


PhpMyadmin situated in https://178.250.xxx.xxx/myadmin

private void button1_Click(object sender, EventArgs e)
        {
 
            server = "178.250.xxx.xxx/myadmin";
            database = "test";
            uid = "test";
            password = "password";
            string connectionString;
            connectionString = "SERVER=" + server + ";" + "DATABASE=" +
            database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
 
            connection = new MySQLConnection(connectionString);
            connection.Open(); // show error
            MySQLCommand cmd;
            cmd = new MySQLDriverCS.MySQLCommand("select * from Code", connection);
            MessageBox.Show(cmd.CommandText);
            cmd.ExecuteNonQuery();
           
        }


MySQLDriverCS Exception: MySQLDriverCS Error: can't connect.Can't connect to MySQL server on 'localhost' (10061)

解决方案

The only possible error I see might be your server string.
Just pass the ip to the connection without the path.
In case your server isn''t listening on the default port (3306), you also should specify it (Port=xyz;)

Best regards


Re-check the connection string using: http://www.connectionstrings.com/mysql[^]


这篇关于从C#连接到MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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