c# - 我如何在我的项目中解决初始化字符串的格式不符合从索引 17' 开始的规范

标签 c# mysql .net

初始化连接

System.ArgumentException:'Format of the initialization string does not conform to specification starting at index 17'

此行显示上述错误消息

    private void InitializeConnection()
    {
        server = "localhost";
        database = "table";
        uid = "root";
        password = "";
        string connectionString = "SERVER=" + server + ";" + "DATABASE" + database + ";" + "UID" + uid + ";" + "PASSWORD" + password + ";";
        ObjConnection = new MySqlConnection(connectionString); // error happens here
    }

enter image description here

最佳答案

DATABASE附近的代码中应该类似于DATABASE=UIDPASSWORD也是如此。所有你在这些变量附近都错过了=

private void InitializeConnection()
{
    server = "localhost";
    database = "table";
    uid = "root";
    password = "";
    string connectionString = "SERVER=" + server + ";" + "DATABASE=" + database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
    ObjConnection = new MySqlConnection(connectionString);
}

关于c# - 我如何在我的项目中解决初始化字符串的格式不符合从索引 17' 开始的规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51107048/

相关文章:

.net - WPF/银光VS WinRT

c# - 如何以编程方式重建现有程序集?

c# - 是否可以更改 Attribute.Add 格式化添加属性的方式?

c# - 如何仅在 TransactionScope 提交时运行自定义 C# 函数?

php - 显示一个字符串两次?

php - 无法将 session 变量存储到数据库中

.net - 使用线程监听 UDP 广播

c# - 假设 this != null 在实现 IComparable<T> 时

MySQL SUM() 对不同列中的相同单元格进行求和

c# - 维基百科 A* 寻路算法需要大量时间