D
darren.pruitt
I am working with a large legacy ASP.NET application that does not (in
my opinion) properly close or dispose of its ADO.NET objects
(connections, commands, transactions, etc.). The web site is under
heavy load so database objects are being created like mad.
My question is this: Will not properly disposing of these objects lead
to memory leaks? Or just garbage collection overload? Or will the
system eventually be brought to its knees gasping for more memory?
A typical code example is:
public static string SomeFunction(int someId)
{
string returnValue = "";
SqlConnection conn = new SqlConnection(AStaticConnectionString);
try
{
conn.Open();
string commandText = "storedProcName";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@some_id", SqlDbType.Int, 4);
param[0].Value = someId;
// Using the Micorsoft SqlHelper Object
returnValue = SqlHelper.ExecuteScalar(conn,
CommandType.StoredProcedure, commandText, param).ToString();
}
catch (SqlException sx)
{
throw sx;
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
return returnValue;
}
my opinion) properly close or dispose of its ADO.NET objects
(connections, commands, transactions, etc.). The web site is under
heavy load so database objects are being created like mad.
My question is this: Will not properly disposing of these objects lead
to memory leaks? Or just garbage collection overload? Or will the
system eventually be brought to its knees gasping for more memory?
A typical code example is:
public static string SomeFunction(int someId)
{
string returnValue = "";
SqlConnection conn = new SqlConnection(AStaticConnectionString);
try
{
conn.Open();
string commandText = "storedProcName";
SqlParameter[] param = new SqlParameter[1];
param[0] = new SqlParameter("@some_id", SqlDbType.Int, 4);
param[0].Value = someId;
// Using the Micorsoft SqlHelper Object
returnValue = SqlHelper.ExecuteScalar(conn,
CommandType.StoredProcedure, commandText, param).ToString();
}
catch (SqlException sx)
{
throw sx;
}
catch (Exception ex)
{
throw ex;
}
finally
{
conn.Close();
}
return returnValue;
}