【问题标题】:im having a problem with this everytime i run my code.. heres my code每次我运行我的代码时我都会遇到这个问题..这是我的代码
【发布时间】:2021-04-04 11:48:22
【问题描述】:
class DB
    {
      private  MySqlConnection connection = new MySqlConnection("server=localhost;port:3306;username=root;password=;database=users_db");
        public void openConnection()
        {
            if (connection.State == System.Data.ConnectionState.Closed)
            {
                connection.Open();
            }
        }
        public void closeConnection()
        {
            if (connection.State == System.Data.ConnectionState.Open)
            {
                connection.Close();
            }
        }
        public MySqlConnection getConnection()
        {
            return getConnection();
        }
    }
}

它成功运行但在登录过程之后..出现异常

  • System.ArgumentException: '关键字不支持。 参数名称:port:3306;username'

【问题讨论】:

标签: c# mysql sql


【解决方案1】:

现在我遇到了这个问题

public MySqlConnection getConnection()
        {
            return getConnection();
        }

System.StackOverflowException: 'System.StackOverflowException' 类型的异常被抛出。'

【讨论】:

  • 你应该在你的问题中更新这个并作为答案发布
  • public MySqlConnection GetConnection() => connection; 并停止使用小写字母命名方法。
【解决方案2】:

问题出在“port”参数中的“:”,必须用“=”指定参数,如本例:

"Server=myServerAddress;Port=1234;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"

page 中有大量示例吗,

【讨论】:

  • @Abdulrahmann 。 . .这回答了您在这里提出的问题。如果您还有其他不同的问题,您应该接受这个答案并提出一个新的问题。
猜你喜欢
  • 2023-01-10
  • 2022-12-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-21
  • 2021-10-23
相关资源
最近更新 更多