You are creating a Windows Forms application that includes the database helper methods
UpdateOrder and UpdateAccount. Each method wraps code that connects to a Microsoft SQL
Server 2005 database, executes a Transact-SQL statement, and then disconnects from the
database. You must ensure that changes to the database that result from the UpdateAccount
method are committed only if the UpdateOrder method succeeds. You need to execute the
UpdateAccount method and the UpdateOrder method. Which code segment should you use?
Answer(s)
- using (TransactionScope ts = new TransactionScope()) { UpdateOrder(); UpdateAccount();ts.Complete();}
- using (TransactionScope ts1 = new TransactionScope()) { UpdateOrder(); using(TransactionScope ts2 =new TransactionScope(TransactionScopeOption.RequiresNew)){ UpdateAccount();ts2.Complete(); }ts1.Complete();}
- using (TransactionScope ts = newTransactionScope(TransactionScopeOption.RequiresNew)){UpdateOrder(); ts.Complete();}using (TransactionScope ts = newTransactionScope(TransactionScopeOption.Required)){ UpdateAccount(); ts.Complete();}
- using (TransactionScope ts = newTransactionScope(TransactionScopeOption.RequiresNew)){UpdateOrder();}using (TransactionScope ts = newTransactionScope(TransactionScopeOption.Required)){UpdateAccount(); ts.Complete();}
Correct Answer using (TransactionScope ts = new TransactionScope()) { UpdateOrder(); UpdateAccount();ts.Complete();}