Which code segment should you insert at line 05?

You create an application by using the Microsoft .NET Framework 3.5 and Microsoft
ADO.NET.You write the following code segment. (Line numbers are included for reference
only.)
01 private void Update (SqlCommand cmdA, SqlCommand cmdB)
02 {
03 using (TransactionScope scope = new TransactionScope())
04 {
05
06 }
07 }
You need to execute the SqlCommand objects named cmdA and cmdB within a single
distributed transaction.Which code segment should you insert at line 05?

You create an application by using the Microsoft .NET Framework 3.5 and Microsoft
ADO.NET.You write the following code segment. (Line numbers are included for reference
only.)
01 private void Update (SqlCommand cmdA, SqlCommand cmdB)
02 {
03 using (TransactionScope scope = new TransactionScope())
04 {
05
06 }
07 }
You need to execute the SqlCommand objects named cmdA and cmdB within a single
distributed transaction.Which code segment should you insert at line 05?

A.
try {
cmdA.Connection.Open();
cmdB.Connection.Open();
cmdA.ExecuteNonQuery();
cmdB.ExecuteNonQuery();
scope.Complete();
}
catch (Exception exp) {}

B.
SqlTransaction trans = null;
try { cmdA.Connection.Open();
using (trans = cmdA.Connection.BeginTransaction()) {
cmdB.Connection = trans.Connection;
cmdB.Connection.Open();
cmdA.ExecuteNonQuery();
cmdB.ExecuteNonQuery();
trans.Commit(); }
} catch (Exception exp) {
trans.Rollback(); }

C.
SqlTransaction trans = null;
try { cmdA.Connection.Open();
cmdB.Connection.Open();
trans = cmdA.Connection.BeginTransaction();
cmdA.Transaction = trans; cmdB.Transaction = trans;
cmdA.ExecuteNonQuery(); cmdB.ExecuteNonQuery();
trans.Commit(); }
catch (Exception exp) {
trans.Rollback();}

D.
SqlTransaction trans = null;
try { cmdA.Connection.Open();
using (trans = cmdA.Connection.BeginTransaction()) {
cmdB.Connection.Open(); cmdA.Transaction = trans;
cmdB.Transaction = trans; cmdA.ExecuteNonQuery();
cmdB.ExecuteNonQuery(); trans.Commit(); }
}catch (Exception exp) {
trans.Rollback();
}



Leave a Reply 0

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