我最近收到了mysql to mysql错误,我使用了下面这样的sql查询
SET GLOBAL max_conmnections = 8000;和ive也会使mysql.pool.max to 8000更高,当我的模拟器在调试器中时,它会在这个空白处崩溃
private static SqlDatabaseClient CreateClient(int Id)
{
MySqlConnection Connection = new MySqlConnection(GenerateConnectionString());
Connection.Open();
return new SqlDatabaseClient(Id, Connection);
}当我收到10-12个在线连接时,模拟器在调试器中运行了7-8个小时,被高亮显示的那行导致它崩溃的代码是connection.open();!
发布于 2013-08-19 16:28:56
您可以尝试在由C# 语句使用后关闭并处置连接和命令:
private static SqlDatabaseClient CreateClient(int Id)
{
Int32 returnId = 0;
try
{
using(MySqlConnection connection = new MySqlConnection(GenerateConnectionString()))
{
connection.Open();
if(connection.State == ConnectionState.Open)
{
returnId = Id;
}
}
}
catch(Exception exception)
{
Console.Write(ex.Message);
}
finally
{
if(connection.State == ConnectionState.Open)
{
connection.Close();
}
}
return returnId;
}发布于 2013-08-19 16:45:25
我建议重写成类似这样的内容:
private static void ExecuteInClientContext(int Id, Action<SqlDatabaseClient> callback) {
if (callback == null) {
throw new ArgumentNullException("callback");
}
using(MySqlConnection Connection = new MySqlConnection(GenerateConnectionString())) {
Connection.Open();
callback.Invoke(new SqlDatabaseClient(Id, Connection));
}
}
static void Foo() {
ExecuteInClientContext(1, (context) => {
// whatever
});
}发布于 2013-08-19 16:46:40
我认为您可以添加如下代码:SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection);然后,在关闭SqlDataReader的实例后,Connection对象也将关闭。
https://stackoverflow.com/questions/18309362
复制相似问题