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) {
foreach (SqlError error in ex.Errors) {
// handle the exception...
}
} catch (Exception ex) {
// handle the exception...
} finally {
// clean up
}
}
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) {
switch (ex.Number) {
case 1:
// handle the exception...
break;
default:
// handle the exception...
break;
}
} catch (Exception ex) {
// handle