Reputation:
This is really simple, all i'm trying to do is fill a datatable, i have everything surrounded by using() and the connection will not dispose/close. Please help
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;
}
Upvotes: 2
Views: 940
Reputation: 6967
Alternatives to Pooling=false
are SqlConnection.ClearPool and SqlConnection.ClearAllPools methods. For more information read: SQL Server Connection Pooling (ADO.NET)
Upvotes: 0
Reputation: 45741
Have you tried:
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();
}
?
Upvotes: 1