C# 模拟器“多连接" [英] C# Emulator 'To Many Connections'

查看:73
本文介绍了C# 模拟器“多连接"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近收到一个 mysql to many connectioniions 错误,我使用了 sql 查询,例如下面的一个

I have recently been receiving a mysql to many connectiions error, ive used sql queries such as the one below

SET GLOBAL max_conmnections = 8000; 并且我还将 mysql.pool.max 提高到 8000 并且当我的模拟器在调试器中时,它会在此空白处崩溃

SET GLOBAL max_conmnections = 8000; and ive also higherd the mysql.pool.max to 8000 and when my emulator is in the debugger, it crashes on this void

private static SqlDatabaseClient CreateClient(int Id)
{
     MySqlConnection Connection = new MySqlConnection(GenerateConnectionString());
     Connection.Open();

     return new SqlDatabaseClient(Id, Connection);
}

突出显示导致它崩溃的行是 connection.open(); 它发生在我收到 10-12 个在线连接时,模拟器在调试器中运行了 7-8 小时!

the line thats highlighted that has caused it to crash was connection.open(); it happens when i receive 10-12 online connections, the emulator was running for 7-8 hours in the debugger!

推荐答案

你可以尝试的是关闭并配置 C# 使用后的连接和命令 使用声明:

What you can try is to close and dispose the connection and commands after used by the C# using statement:

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;
}

这篇关于C# 模拟器“多连接"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆