This is a follow up question to this question:
Correct use of Try Catch for the SQL connection in C#
when you write a code like:
using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
using (SqlCommand cmd = new SqlCommand(queryGetPcPrintDetails, connection))
{
using (SqlDataReader reader = cmd.ExecuteReader())
{
if (reader != null)
{
while (reader.Read())
{
//do stuff
}
}
} // reader closed and disposed up here
} // command disposed here
}
Is there a need to catch an exception in order to close the connection? For example, if there's some problem in the second using or in the do stuff section.. do I need to somehow do try/finally and close the connection?