gpt4 book ai didi

c# - 如何在连接字符串中使用 ip 地址和用户名?

转载 作者:行者123 更新时间:2023-11-29 17:57:02 25 4
gpt4 key购买 nike

我编写了这个方法,但如果“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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com