Dave

Dave

  • NA
  • 161
  • 0

Question about exception handling

Jan 24 2008 8:43 PM
Hi,

The prevailing wisdom for coding try/catch statements around db connections seems to be as follows:
conn = new MySqlConnection();
cmdGetDate = new MySqlCommand();
try
{
    conn.ConnectionString = connStringSQL;
    conn.Open();

    ...do some stuff   
}
catch (Exception dbErr)
{
    throw new Exception(dbErr.Message);   
}
finally
{
    conn.Close();
    cmdGetDate.Dispose();
    conn.Dispose();
}
My question is, what if an exception occurs on closing the connection (which is inside the finally part of the try/catch)?

Answers (2)