Which line of code should you insert at line 21?

You use Microsoft .NET Framework 4.0 to develop an application that connects to two separate Microsoft SQL Server 2008 databases.
The Customers database stores all the customer information, and the Orders database stores all the order information.
The application includes the following code. (Line numbers are included for reference only.)

01 try
02 {
03 conn.Open();
04 tran = conn.BeginTransaction(“Order”);
05 SqlCommand cmd = new SqlCommand();
06 cmd.Connection = conn;
07 cmd.Transaction = tran;
08 tran.Save(“save1”);
09 cmd.CommandText = “INSERT INTO [Cust].dbo.Customer ” + “(Name, PhoneNumber) VALUES (‘Paul Jones’, ” + “‘404-555-1212’)”;
10 cmd.ExecuteNonQuery();
11 tran.Save(“save2”);
12 cmd.CommandText = “INSERT INTO [Orders].dbo.Order ” + “(CustomerID) VALUES (1234)”;
13 cmd.ExecuteNonQuery();
14 tran.Save(“save3”);
15 cmd.CommandText = “INSERT INTO [Orders].dbo.” + “OrderDetail (OrderlD, ProductNumber) VALUES” + “(5678, ‘DC-6721’)”;
16 cmd.ExecuteNonQuery();
17 tran.Commit();
18 }
19 catch (Exception ex)
20 {
21 …
22 }

You run the program, and a timeout expired error occurs at line 16. You need to ensure that the customer information is saved in the database.
If an error occurs while the order is being saved, you must roll back all of the order information and save the customer information.
Which line of code should you insert at line 21?

You use Microsoft .NET Framework 4.0 to develop an application that connects to two separate Microsoft SQL Server 2008 databases.
The Customers database stores all the customer information, and the Orders database stores all the order information.
The application includes the following code. (Line numbers are included for reference only.)

01 try
02 {
03 conn.Open();
04 tran = conn.BeginTransaction(“Order”);
05 SqlCommand cmd = new SqlCommand();
06 cmd.Connection = conn;
07 cmd.Transaction = tran;
08 tran.Save(“save1”);
09 cmd.CommandText = “INSERT INTO [Cust].dbo.Customer ” + “(Name, PhoneNumber) VALUES (‘Paul Jones’, ” + “‘404-555-1212’)”;
10 cmd.ExecuteNonQuery();
11 tran.Save(“save2”);
12 cmd.CommandText = “INSERT INTO [Orders].dbo.Order ” + “(CustomerID) VALUES (1234)”;
13 cmd.ExecuteNonQuery();
14 tran.Save(“save3”);
15 cmd.CommandText = “INSERT INTO [Orders].dbo.” + “OrderDetail (OrderlD, ProductNumber) VALUES” + “(5678, ‘DC-6721’)”;
16 cmd.ExecuteNonQuery();
17 tran.Commit();
18 }
19 catch (Exception ex)
20 {
21 …
22 }

You run the program, and a timeout expired error occurs at line 16. You need to ensure that the customer information is saved in the database.
If an error occurs while the order is being saved, you must roll back all of the order information and save the customer information.
Which line of code should you insert at line 21?

A.
tran.Rollback();

B.
tran.Rollback(“save2”);
tran.Commit();

C.
tran.Rollback();
tran.Commit();

D.
tran.Rollback(“save2”);

Explanation:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqltransaction.save.aspx
http://msdn.microsoft.com/en-us/library/4ws6y4dy.aspx



Leave a Reply 0

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