PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

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?

PrepAway - Latest Free Exam Questions & Answers

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();
}


Leave a Reply