C# mysql中的连接错误太多
我有一个连接mysql数据库服务器的C#桌面应用程序。 应用程序运行良好,但经过一段时间或几天之后,会出现如下异常:C# mysql中的连接错误太多,c#,mysql,C#,Mysql,我有一个连接mysql数据库服务器的C#桌面应用程序。 应用程序运行良好,但经过一段时间或几天之后,会出现如下异常: 9/16/2013 12:56:55 PM: 9/16/2013 12:56:55 PM: Exception Occurred. Too many connections.StackTrace: at MySql.Data.MySqlClient.MySqlStream.OpenPacket() at MySql.Data.MySqlClient.NativeDr
9/16/2013 12:56:55 PM: 9/16/2013 12:56:55 PM: Exception Occurred. Too many
connections.StackTrace: at MySql.Data.MySqlClient.MySqlStream.OpenPacket()
at MySql.Data.MySqlClient.NativeDriver.Authenticate411()
at MySql.Data.MySqlClient.NativeDriver.Authenticate()
at MySql.Data.MySqlClient.NativeDriver.Open()
at MySql.Data.MySqlClient.MySqlConnection.Open()
at ReckonHelper.MySqlDatabaseConnection.ConnectDB().
我不知道为什么会发生这种事
有什么解决办法吗
try
{
.......
con.Open();
//execute sql statement
}
catch (Exception ex)
{
throw ex;
//throw or dispaly your exception
}
finally
{
con.close;
}
“服务器=服务器名;端口=3306;数据库=数据库名;Uid=用户名;Pwd=密码;池=真;允许零日期时间=真;最小池大小=5;最大池大小=100;”
您是否在任何地方关闭/处理连接?如果您忘记关闭和处理打开的连接,这种情况在MySql中非常常见。请记住,如果处理不当,异常可能会留下打开的连接。()我使用了close commandOr better
使用(..{…}
嗯,我使用了try..catch..Finally。第二个选项:设置池属性应该有效;在MySQl GUI上。它将显示连接数据库的当前进程列表。如果您看到更多进程列表,只需杀死所有不需要的进程(参考:)