我编写了这个方法,但如果“uid”中有 ' 符号,它会抛出 System.ArgumentException。
public void Init(string constr)
{
var server = "a222068_6.mysql.mchost.ru";
var database = "'a222068_6'";
var uid = "'a222068_6'@'10.0.2.13'";
var pass = "pass";
constr = "SERVER=" + server + ";DATABASE=" + database + ";UID=" + uid + ";PASSWORD=" + pass + ";SSL Mode=None;";
cnt = new MySqlConnection(constr); // Exception is thrown here
}
尝试在没有 ' 的情况下进行连接时出现异常消息
Authentication to host 'a222068_6.mysql.mchost.ru' for user 'a222068_6@10.0.2.13' using method 'mysql_native_password' failed with message: Access denied for user 'a222068_6@10.0.2.13'@'localhost' (using password: YES)
最佳答案
改变
var uid = "'a222068_6'@'10.0.2.13'";
到
var uid = @"a222068_6@10.0.2.13";
关于c# - 如何在连接字符串中使用 ip 地址和用户名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48713356/