Friday 18 January 2008

Transactions in .Net

3 types of transactions:

ADO.Net Transaction (System.Data)
Limited to one database connection.


Enterprise services transactions. (System.ComponentModel)
- Uses the 2 phase commit protocol
- Needs a distributed transaction manager.

Transaction (System.Transactions)
Transactions taking advantage of the above two. It can determine whether or not to use a distributed transaction. For example, it uses a lightweight transaction in case of a single database connection or an operation which needs to be performed in the same network domain.

Use a transaction scope to "scope" a method/operation.
- required: If the operation has a TransactionScope.Required attribute, it joins the existing transaction scope or creates a new one if it does not exist.
- RequiresNew: Creates a transaction for each operation.
- Suppress: The operation will never be part of a transaction.

Transaction Isolation level:
- READ COMMITTED: we can only read committed data..
- SERIALIZABLE: Prevents other users from inserting/updating data until the transaction is complete. Most restrictive level.
- REPEATABLE READ : Shared locks are used for reading data. No dirty reads.
- READ UNCOMMITTED: No shared locks while reading data. Possible dirty reads.

No comments: