我收到错误:
Could not establish a connection to database
当我使用 MySQL .NET 连接器连接时。我完全确定用户名是对的,密码是对的,数据库是对的,服务器是对的。代码如下:
mysqlCon.ConnectionString = "Server=(servername);Username=(username);Pwd=(rightpassword);
Database=(rightdatabase)";
try
{
mysqlCon.Open();
}
catch (Exception ex)
{
MessageBox.Show("Could not establish a connection to database!");
}
最佳答案
您不应该使用Uid
而不是Username
吗?至少connectionstrings.com这么说:)
还要检查您的 MySQL 运行在哪个端口。如果您不使用默认端口号 - 3306
,则可能需要将端口号添加到连接字符串中。
关于c# - 使用 MySQL.NET 连接器连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5605560/