Transactions in 'NET - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Transactions in 'NET

Description:

Modifications made by concurrent transactions must be isolated from the ... Classes inherit from ServicedComponent and interact with COM more directly. 9/29/09 ... – PowerPoint PPT presentation

Number of Views:38
Avg rating:3.0/5.0
Slides: 19
Provided by: busOreg
Category:

less

Transcript and Presenter's Notes

Title: Transactions in 'NET


1
Transactions in .NET
2
Agenda
  • Overview
  • Transactions in T-SQL
  • Transactions in ADO.NET
  • Transactions in COM

3
What is a Transaction?
  • A transaction is a set of related tasks that
    either succeed or fail as a unit.

4
ACID
  • Atomicity
  • A transaction must be an atomic unit of work
    either all of its data modifications are
    performed, or none of them is performed.
  • Consistency
  • When completed, a transaction must leave all data
    in a consistent state.
  • Isolation
  • Modifications made by concurrent transactions
    must be isolated from the modifications made by
    other concurrent transactions.
  • Durability
  • After a transaction has completed, its effects
    are permanently in place in the system.

5
Transaction Log
  • The transaction log records the start of each
    transaction. It records the changes to the data
    and enough information to undo the modifications
    (if necessary later) made during each transaction

6
.NET Transactions
  • Automatic
  • Manual

7
Manual Transactions
  • SqlTransaction Class
  • SqlConnection.BeginTransaction()
  • conn.Open()
  • SqlTransaction trans conn.BeginTransaction()

8
Manual Transactions
  • trans.Commit()
  • trans.Rollback()
  • trans.IsolationLevel
  • try
  • //Execute db stuff here
  • //Note that trans must be set for each command
  • trans.Commit()
  • catch
  • trans.Rollback()

9
Automatic Transactions
  • Pages and Web Services can simply be marked as
    requiring transactions.
  • Classes inherit from ServicedComponent and
    interact with COM more directly

10
Automatic Transactions - Page
  • lt_at_ Page Transaction"Required" gt
  • Disabled
  • Not Supported
  • Supported
  • Required
  • RequiresNew

11
Automatic Transactions - Webmethods
  • WebMethod(TransactionOptionTransactionOption.Re
    quiresNew)
  • public void MyWebMethod()

12
Automatic Transactions
  • Examples

13
Automatic Transactions - Class
  • Apply the TransactionAttribute to your class.
  • Derive your class from the ServicedComponent
    Class.
  • Sign the assembly with a strong name.
  • Add the AssemblyKeyFileAttribute or
    AssemblyKeyNameAttribute assembly attribute
  • Register the assembly that contains your class
    with the COM catalog.

14
Automatic Transactions - Class
  • //COM application name in the COM catalog.
  • assembly ApplicationName("TestApp")
  • //Strong name for assembly.
  • assembly AssemblyKeyFileAttribute("TestApp.snk")
  • //Transaction Requirements
  • Transaction(TransactionOption.Required)
  • public class Account ServicedComponent

15
Automatic Transactions Class
  • Transaction(TransactionOption.Supported)
  • public class Account ServicedComponent
  • AutoComplete
  • public void Debit(int amount)
  • // Do some database work.
  • // Any exception thrown here aborts the
    transaction
  • // otherwise, transaction commits.
  • You can also use ContextUtil.SetAbort() and
    ContextUtil.SetComplete() to vote on completion
    of the transaction (in distributed transactions)

16
Discussion
  • How to best transact object models?

17
Summary
  • Transactions and ACID Good Trip
  • No Transactions Bad Trip

18
Where to Get More Information
  • SQL Books Online
  • VS.NET Docs
  • Professional ADO.NET
Write a Comment
User Comments (0)
About PowerShow.com