|
|
| Home >> Microsoft Certification >> MCSD >> Questions/Answers on Exam 070-305 >> QA10 |
Question:
You are creating an ASP.Net page and writing a code in it to run a group of stored procedures which will perform the updation in the database at the end of each month. You use OleDbConnection object to connect to the database and OleDbCommand object to run the set of stored procedures. You want the changes made in the database to be committed only if all the stored procedures execute successfully but if an error occurs during the execution of any of the stored procedure then you want to roll back any database changes that where posted. You write code to catch an OleDbException object if an error occurs during the execution of a stored procedure. What else should you do?
A. Call the BeginTransaction method of the OleDbConnection object before running the stored procedure. If an error occurs, use the OleDbConnection object to roll back the changes.
B. Use the Begin Transaction method of the OleDbConnection object to create an OleDbTransaction object. Assign the OleDbTransaction object to the Transaction property of your OleDbCommand object. If an error occurs, use the OleDbTransaction object to roll back the changes.
C. Call the BeginTransaction method of the OleDbConnection object before running the stored procedures. If an error occurs, use the OleDbException object to roll back the changes.
D. Use the BeginTransaction method of the OleDbConnection object to create an OleDbTransaction object. Pass a reference to the OleDbTransaction object to each stored procedure. Use error handling inside the stored procedures to roll back the changes.
Correct Answer:
B
Explanation:
First we create OleDbTransaction object and then assign OleDbTransaction object to the transaction property of OleDbCommand object. Finally we should have an appropriate exception handling code to roll back the changes in a proper and efficient way.
Incorrect Answers
A, C: We must create an OleDbTransaction object for the transaction.
D: We should not pass a reference to the OleDBTransaction. Instead we set the OleDbCommand.Transaction property to the transaction.
|
| Sponsored Links: |
|
|
| << back |
|
|
|