R
Raymon
I have this method in a data utility class used to retrieve data from
sql server.
It only checks for sever deadlock in which case it will retry the
operation 10 times before giving up.
Any other error is thrown back to the caller.
When I run code analysis on this it gives the warning datatable dt
is not disposed of in all exception paths.
How can I dispose of the datatable?
It is the very data that is being returned.
public static DataTable GetTable(SqlCommand cmd)
{
bool done = false;
int tries = 0;
DataTable dt = new DataTable();
while (!done)
{
try
{
using (SqlDataAdapter adp = new SqlDataAdapter(cmd))
{
adapter.Fill(dt);
}
done = true;
}
catch (SqlException e)
{
foreach (SqlError er in e.Errors)
{
if (er.Number == 1205 && tries < 10)
{
tries++;
System.Threading.Thread.Sleep(5);
break;
}
else
{
throw;
}
}
}
}
return dt;
}
sql server.
It only checks for sever deadlock in which case it will retry the
operation 10 times before giving up.
Any other error is thrown back to the caller.
When I run code analysis on this it gives the warning datatable dt
is not disposed of in all exception paths.
How can I dispose of the datatable?
It is the very data that is being returned.
public static DataTable GetTable(SqlCommand cmd)
{
bool done = false;
int tries = 0;
DataTable dt = new DataTable();
while (!done)
{
try
{
using (SqlDataAdapter adp = new SqlDataAdapter(cmd))
{
adapter.Fill(dt);
}
done = true;
}
catch (SqlException e)
{
foreach (SqlError er in e.Errors)
{
if (er.Number == 1205 && tries < 10)
{
tries++;
System.Threading.Thread.Sleep(5);
break;
}
else
{
throw;
}
}
}
}
return dt;
}