gpt4 book ai didi

C# MySQL 连接问题

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

我正在尝试将 C# 应用程序(使用 Visual C# 2008 Express Edition)连接到远程 MySQL 服务器。我有这方面的驱动程序,但是当我遵循教程(包括添加池和连接重置属性)时,我收到一个错误:未将对象引用设置为对象的实例。我'已经包含了应该建立连接的两行代码。错误在第二行抛出。

        MySqlConnection connect = new MySqlConnection("database=d*******;Data Source=mysql.netfirms.com;user id=*******;pwd=*****;pooling=false;connection reset=false");
connect.Open();

最佳答案

我会尝试在构造函数之外设置连接字符串以帮助缩小问题范围:

MySqlConnection connect = new MySqlConnection();
//Do you get the null exception in this next line?
connect.ConnectionString = "your conn string here";
connect.Open(); //-> If you get the exception here then the problem is with the connection string and not the MySqlConnection constructor.

如果您确实在 connect.ConnectionString = ... 行中遇到异常,那么问题出在驱动程序上,听起来您需要重新安装它。

我也会尝试一个更简单的连接字符串,没有池和重置键。

关于C# MySQL 连接问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/403398/

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