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.

You need to separate the security-related exceptions from the other exceptions for database operations at run time.

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.

You need to separate the security-related exceptions from the other exceptions for database operations at run time.

Which code segment should you use?

A.
catch (System.Security.SecurityException ex)
{
//Handle all database security related exceptions.
}

B.
catch (System.Data.SqlClient.SqlException ex)
{
for (int i = 0; i < ex.Errors.Count; i++)
{
if (ex.Errors[i].Class.ToString() == "14")
{
//Handle all database security related exceptions.
}
else
{
//Handle other exceptions
}
}
}

C.
catch (System.Data.SqlClient.SqlException ex)
{
for (int i = 0; i < ex.Errors.Count; i++)
{
if (ex.Errors[i].Number == 14)
{
//Handle all database security related exceptions.
}
else
{
//Handle other exceptions
}
}
}

D.
catch (System.Data.SqlClient.SqlException ex)
{
for (int i = 0; i < ex.Errors.Count; i++)
{
if (ex.Errors[i].Message.Contains("Security"))
{
//Handle all database security related exceptions.
}
else
{
//Handle other exceptions
}
}
}



Leave a Reply 0

Your email address will not be published. Required fields are marked *