MySQL连接器打开连接时超时
本文关键字:超时 连接 连接器 MySQL | 更新日期: 2023-09-27 18:06:34
我有以下类:
public class MySqlConnectionManager
{
public MySqlConnection Connection { get; set; }
public void OpenConnection()
{
Connection = new MySqlConnection(GetConnectionString());
try
{
Connection.Open();
}
catch (MySqlException exc)
{
switch (exc.Number)
{
case 0:
throw new Exception("Cannot connect to MySQL-server. Please contact administrator.");
case 1045:
throw new Exception("Invalid username/password to connect to MySQL-server. Please correct data.");
default:
throw new Exception("Unknown MySQL-connection error. Code: " + exc.Number);
}
}
}
private string GetConnectionString()
{
string activeDatabaseServer;
string activeDatabaseName;
string activeDatabaseUsername;
string activeDatabasePassword;
#if DEBUG
activeDatabaseServer = DebugDatabaseServer;
activeDatabaseName = DebugDatabaseName;
activeDatabaseUsername = DebugDatabaseUsername;
activeDatabasePassword = DebugDatabasePassword;
#else
activeDatabaseServer = ReleaseDatabaseServer;
activeDatabaseName = ReleaseDatabaseName;
activeDatabaseUsername = ReleaseDatabaseUsername;
activeDatabasePassword = ReleaseDatabasePassword;
#endif
string connectionString = "server=" + activeDatabaseServer + ";uid=" + activeDatabaseUsername + ";pwd=" +
activeDatabasePassword + ";database=" + activeDatabaseName + ";";
return connectionString;
}
当Connection.Open()被调用时,我得到一个超时异常。将超时时间设置为120秒也无济于事。我的调试数据库工作(它在本地)。我只在释放模式下得到这个异常。但我确信服务器,数据库,用户名和密码的名称是正确的,因为我使用相同的数据库从另一个应用程序编写的php在那里一切都很好。
密码包含特殊字符,如'!', '%', '*', '。'或'@'。这有什么麻烦吗?
我的代码运行在一个外部系统上。不可能从外部连接到1&1托管的mysql-数据库。(