2

这真的很简单,我要做的就是填充数据表,我将所有内容都包围在 using() 中,并且连接不会释放/关闭。请帮忙

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

3 回答 3

3

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

于 2012-07-13T15:15:58.320 回答
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();
     }

?

于 2012-07-13T14:51:29.657 回答
0

替代方法Pooling=falseSqlConnection.ClearPoolSqlConnection.ClearAllPools方法。有关详细信息,请阅读:SQL Server 连接池 (ADO.NET)

于 2014-04-23T12:05:00.377 回答