Transaction is the most crucial feature for data integrity
Control the application flow when transaction is throw an exception (i.e. Showing friendly message)
2. Background
• Transaction is the most crucial feature for data
integrity
• Control the application flow when transaction
is throw an exception (i.e. Showing friendly
message)
3. Objective
• As decision support to choose the right
technology or right concept for handle
transaction process in .NET stack based on our
environment
4. .NET Transaction Architecture
Based on my environment i’m just do
an atomic transaction which is there
are no multiple open connection or
connect into third party database
(i.e.Java-Tomcat) in single transaction.
The red boundary mean focus on
atomic transaction
5. Technology Options
• TransactionScope
– Not part of ADO.NET
– Developed by the Enterprise Service team at
Microsoft
– Available in System.Transactions
– Called Ambient Transaction is not tied just to a
database, any transaction aware provider can be used
• SqlTransaction
– Part of ADO.NET
– Called Connection Transaction because is tied directly
with a database connection
6. Matrix Comparison
Concern TransactionScope SqlTransaction
Performance Good (local transaction) Good
Flexibility Good, cover Automatic
Distribution Transaction Handling
Ordinary
Maintainability More simple, when dealing
with multi database
Simple
Ease of use Simple Simple
Hint Loose-coupling
Its like a Jacket or Cloak
support any RDBMS and
non-database process like
rollback creational of
directory inside the
transaction (Ambient
Transaction)
Tighly-coupling with the
specific RDBMS
7. Transaction Behaviors
Concern TransactionScope SqlTransaction
Rollback inserted data.
Is the auto increment id
can be reused?
NO NO
Rollback updated data.
Is the auto increment id
can be reused?
YES YES
Rollback deleted data.
Is the auto increment id
can be reused?
YES YES
Common behavior:
1. Row Locking will be used for operation UPDATE and DELETE but SQL
may decide to escalate it if it runs low on resources, can be
depending on the indexes and load on the server it may end up
escalating to a Page Lock or Table Locking
2. Table Locking will used for operation INSERT
8. Suggestion
• Use the TransactionScope is better than the
SqlTransaction in term of Flexibility
• Flexibility is good investment, it’s like the
system can be more adaptive for changes
• The flexibility, will make it easier in the future
to include things other than ADO.NET calls
into a transaction.
9. What we choose?
• To Team leader
– you can decide by your own
– or you can discuss with the team member and do
a vote for choose the options
• To deep dive understanding about Transaction
beside the architecture, we must know about
the SQL Server 2008 R2 transaction behaviors