请问C#程序里面插入比较多数据(500条记录)的时候提示如下错误:MySQLDriverCS Exception: MySQLDriverCS Error: can't connect.Can't connect to MySQL server on 'xxxx.xxxx.xxx.xx' (10048)该如何排查?

解决方案 »

  1.   

    mysql> show status like 'max_used_connections';
    +----------------------+-------+
    | Variable_name        | Value |
    +----------------------+-------+
    | Max_used_connections | 93    | 
    +----------------------+-------+
    1 row in set (0.00 sec)mysql>  show variables like 'max_connections';
    +-----------------+-------+
    | Variable_name   | Value |
    +-----------------+-------+
    | max_connections | 1000  | 
    +-----------------+-------+
    1 row in set (0.00 sec)
      

  2.   

    你的INSERT在C#中有没有及时关闭连接? 不会使用的什么 sqlhelp 之类的东西吧。
      

  3.   

    通过静态方法insert每次都关闭connection呢,难道sqlhelp是不能使用?
      

  4.   

            public static int ExecuteNonQuery(string cmdText, MySQLParameter[] parameters)
            {
                int i = 0;
                using (MySQLConnection conn = new MySQLConnection(DataBaseConnectionString.MySqlStr))
                {
                    try
                    {
                        conn.Open();
                        MySQLCommand command = new MySQLCommand { Connection = conn };
                        foreach (var p1 in parameters)
                        {
                            command.Parameters.Add(p1);
                        }
                        command.CommandText = cmdText;
                        i = command.ExecuteNonQuery();                }
                    catch (Exception ex)
                    {
                        i = -1;                                   }
                    finally
                    {
                        conn.Close();
                    }
                }            return i;
            }
      

  5.   

     你的conn并没有dipose掉啊。建议到.net群中去咨询一下,似乎conn.close后并不立即释放连接。
      

  6.   

    查看 MySQLConnection 这个类  对  close 方法的封装
    非c#人员的建议说个题外话,不知道楼主的的 server是一个人用还是多人在用,上述方法只是代表服务器只被你一个人使用所以才去查找代码原因,如果是多人都在大批量插入,就。。
      

  7.   

    进到mysql服务器,show processlist之类的,看看有多少连接,是不是超了?
    另外,物理排查一下,是否还能连上mysql数据库。
      

  8.   

    查询一下具体进程show processlist是否超过了连接数。