New Year Sale Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: simple70

GIAC GIAC Secure Software Programmer - C#.NET GSSP-NET-CSHARP Question # 60 Topic 7 Discussion

GIAC GIAC Secure Software Programmer - C#.NET GSSP-NET-CSHARP Question # 60 Topic 7 Discussion

GSSP-NET-CSHARP Exam Topic 7 Question 60 Discussion:
Question #: 60
Topic #: 7

You work as a Software Developer for ABC Inc. The company uses Visual Studio .NET 2005 as its application development platform. You are developing the data access component that all applications in your company intranet will use to access Microsoft SQL Server. You must include code to correctly catch and iterate through any number of errors that could be encountered when connecting to SQL Server. Which code segment should you choose?


A.

string connectionString =

"server=(local); database=Northwind;"

+ "integrated security=true;";

using (SqlConnection cnn = new SqlConnection(connectionString)){

try {

cnn.Open();

} catch (Exception ex) {

// handle the exception...

} catch (SqlException ex) {

foreach (SqlError error in ex.Errors) {

// handle the exception...

}

} finally {

// clean up

}

}


B.

string connectionString =

"server=(local); database=Northwind;"

+ "integrated security=true;";

using (SqlConnection cnn = new SqlConnection(connectionString))}

try {

cnn.Open();

} catch (SqlException ex) {

switch (ex.Number) {

case 1:

// handle the exception...

break;

default:

// handle the exception...

break;

}

} catch (Exception ex) {

// handle


C.

string connectionString =

"server=(local); database=Northwind;"

+ "integrated security=true;";

using (SqlConnection cnn = new SqlConnection(connectionString)){

try {

cnn.Open();

} catch (SqlException ex) {

switch (ex.Number) {

case 1:

// handle the exception...

break;

default:

// handle the exception...

break;

}

} catch (Exception ex) {

// handle


D.

string connectionString =

"server=(local); database=Northwind;"

+ "integrated security=true;";

using (SqlConnection cnn = new SqlConnection(connectionString)){

try {

cnn.Open();

} catch (SqlException ex) {

foreach (SqlError error in ex.Errors) {

// handle the exception...

}

} catch (Exception ex) {

// handle the exception...

} finally {

// clean up

}

}


Get Premium GSSP-NET-CSHARP Questions

Contribute your Thoughts:


Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.