MySQL连接不会关闭

时间:2012-07-13 14:43:01

标签: c# mysql

这很简单,我要做的就是填充一个数据表,我有使用()包围的所有内容,连接将不会处理/关闭。请帮忙

DataTable loginTbl = MySQLProcessing.MySQLProcessor.StoreProcedureDTTable("Login", ParamArgs, "Login");


 public static DataTable StoreProcedureDTTable(string mysqlQuery, List<string> CommandArgs, string queryName)
    {

        DataTable DTTableTable = new DataTable();
        using (MySqlCommand MySQLCommandFunc = new MySqlCommand(mysqlQuery))
        {
            MySQLCommandFunc.CommandType = CommandType.StoredProcedure;
            foreach (string args in CommandArgs)
            {
                string[] splitArgs = args.Split('|');
                MySQLCommandFunc.Parameters.AddWithValue(splitArgs[0], splitArgs[1]);
            }
            using (MySqlDataAdapter DataDTTables = new MySqlDataAdapter(MySQLCommandFunc))
            {
                DataDTTables.SelectCommand.CommandTimeout = 240000;
                lock (_object)
                {
                    using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["mysqlCon"].ConnectionString))
                    {
                        MySQLCommandFunc.Connection = con;
                        DataDTTables.Fill(DTTableTable);
                    }

                }
            }
        }
        DataTable catchConnectionTable = DTTableTable;
        DTTableTable.Dispose();
        return catchConnectionTable;
    }

3 个答案:

答案 0 :(得分:3)

将Pooling = False添加到连接字符串

答案 1 :(得分:1)

你试过了吗?

      using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["mysqlCon"].ConnectionString))
      {
           con.open();
           MySqlDataAdapter DataDTTables = new MySqlDataAdapter(MySQLCommandFunc)
           DataDTTables.SelectCommand.CommandTimeout = 240000;
           MySQLCommandFunc.Connection = con;
           DataDTTables.Fill(DTTableTable);
           con.close();
     }

答案 2 :(得分:0)

Pooling=false的替代方法是SqlConnection.ClearPoolSqlConnection.ClearAllPools方法。有关更多信息,请阅读:SQL Server Connection Pooling (ADO.NET)