2
Reply

Question about exception handling

Dave

Dave

Jan 24 2008 8:43 PM
3.1k
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)