I am upgrading an old massive website that is a Classic ASP \ ASP.NET hybrid. I still have a long way to MVC.
Right now I want to convert all code that uses ODBC to the mysql connector specific code.
I've made these 2 functions:
1:
DataTable GetData(string query, List<MySqlParameter> sqlParams, string sComment="")
{
DataTable dt_tmp = new DataTable();
if (sqlParams==null)
sqlParams = new List<MySqlParameter>();
Trace.Write(sComment, GenerateSQLString(query, sqlParams));
using(MySqlDataReader myReader = MySqlHelper.ExecuteReader(sCon, query, sqlParams.ToArray()))
{
dt_tmp.Load(myReader, LoadOption.OverwriteChanges);
}
return dt_tmp;
}
2:
DataTable ReadData(string query, List<MySqlParameter> sqlParams, string sComment="")
{
DataTable dt_tmp = new DataTable();
if (sqlParams==null)
sqlParams = new List<MySqlParameter>();
Trace.Write(sComment, GenerateSQLString(query, sqlParams));
using(MySqlConnection myConnection = new MySqlConnection(sCon))
{
using(MySqlCommand myCommand = myConnection.CreateCommand())
{
myCommand.CommandText = query;
myCommand.Parameters.AddRange(sqlParams.ToArray());
using (MySqlDataAdapter myAdapter = new MySqlDataAdapter(myCommand))
{
myAdapter.Fill(dt_tmp);
}
}
}
return dt_tmp;
}
Function #1: gets a ConstraintException (MaxLength)
on a specific call... but otherwise performs very well.
Which one will perform better? (Ignoring the fact one throws an exception, which I can handle)
My goal is to have the connection open for the minimum amount of time possible so it won't use all connections from the pool.