You need to ensure that after Proc1 executes…

DRAG DROP
You have an application that accesses a Microsoft SQL Server database.
The database contains a stored procedure named Proc1. Proc1 accesses several rows of data across
multiple tables.
You need to ensure that after Proc1 executes, the database is left in a consistent state. While Proc1
executes, no other operation can modify data already read or changed by Proc1. (Develop the
solution by selecting and ordering the required code snippets.
You may not need all of the code snippets.)

DRAG DROP
You have an application that accesses a Microsoft SQL Server database.
The database contains a stored procedure named Proc1. Proc1 accesses several rows of data across
multiple tables.
You need to ensure that after Proc1 executes, the database is left in a consistent state. While Proc1
executes, no other operation can modify data already read or changed by Proc1. (Develop the
solution by selecting and ordering the required code snippets.
You may not need all of the code snippets.)

Answer: See the explanation

Explanation:
Box 1:

Box 2:

Box 3:

Box 4: transaction.Commit();
Box 5:

Box 6: transaction.Rollback();
Box 7: } finally {
Box 8:

Note:
* Box 1: Start with the sqlconnection
* Box 2: Open the SQL transaction (RepeatableRead)
/ IsolationLevel
Specifies the isolation level of a transaction.
/ RepeatableRead
Volatile data can be read but not modified during the transaction. New data can be added during the
transaction.
/ ReadCommitted
Volatile data cannot be read during the transaction, but can be modified.
/ ReadUncommitted
Volatile data can be read and modified during the transaction.
Box 3: Try the query
Box 4: commit the transaction
Box 5: Catch the exception (a failed transaction)
Box 6: Rollback the transaction
Box 7: Final cleanup
Box 8: Clean up (close command and connection).

SqlConnection.BeginTransaction Method
Incorrect:
The transaction is not set up by transactionscope here. Begintransaction is used.



Leave a Reply 2

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


Alper Özagac

Alper Özagac

7,1,5,10,8,9,3,4

Lord Vader

Lord Vader

ReadCommitted
Shared locks are held while the data is being read to avoid dirty reads, but the data can be changed before the end of the transaction, resulting in non-repeatable reads or phantom data.
ReadUncommitted
A dirty read is possible, meaning that no shared locks are issued and no exclusive locks are honored.
RepeatableRead
Locks are placed on all data that is used in a query, preventing other users from updating the data. Prevents non-repeatable reads but phantom rows are still possible.

7,1,5,10,8,9,3,4