You create an application by using the Microsoft .NET Framework 3.5 and Microsoft ADO.NET. The application connects to a Microsoft SQL Server 2005 database.
The application throws an exception when the SQL Connection object is used. You need to handle the exception.
Which code segment should you use?
A.
try
{
if(null!=conn)
conn.Close();
// code for the query
}
catch (Exception ex)
{
// handle exception
}
finally
{
if(null==conn)
conn.Open();
}
B.
try
{
conn.Close();
// code for the query
}
catch (Exception ex)
{
// handle exception
}
finally
{
if(null!=conn)
conn.Open();
}
C.
try
{
conn.Open();
// code for the query
}
catch (Exception ex)
{
// handle exception
}
finally
{
if(null!=conn)
conn.Close();
}
D.
try
{
conn.Open();
// code for the query
}
catch (Exception ex)
{
// handle exception
}
finally
{
if(null==conn)
conn.Close();
}