Title: Transaction Management
1 Transaction Management Using .NET Serviced
Components and COM Services
Speaker ???, Doff Park Feel_at_NET Senior
Consultant ForAce, WebTime ???? MCSD, MCT, CTT
2Agenda
- Introduction to Transaction Management
- Overview of COM Services and the .NET Serviced
Components - Creating .NET Serviced Components
- QA
Transaction Management Using .NET Serviced
Components and COM Services
3Introduction to Transaction Management
- General Idea of Transactions
- An Example of Transaction
- Local Transactions
- Distributed Transactions
- .NET Enterprise Services Transactions
Transaction Management Using .NET Serviced
Components and COM Services
4Introduction to Transaction Management
General Idea of Transactions
- A transaction is a set of separate but
interdependent changes that are made to some
persistent data and that must be performed
together as an atomic operation - ACID Properties
- Atomicity
- Consistency
- Isolation
- Durability
Transaction Management Using .NET Serviced
Components and COM Services
Page 4
5Introduction to Transaction Management
?
An Example of Transactions
Normal Transfer
Abnormal Transfer
Transaction Management
Error
Debit
Credit
Transaction Management Using .NET Serviced
Components and COM Services
Page 5
6Introduction to Transaction Management
Local Transactions
- Multiple select, insert, update, and delete
operations are composed into a single atomic
operation - Local Transactions can be created by using
- Transact-SQL
- ADO.NET
Transaction Management Using .NET Serviced
Components and COM Services
Page 6
7Introduction to Transaction Management
?
Distributed Transactions
- Microsoft Distributed Transaction Coordinator
(DTC) - Manages connections to multiple databases
- Manages connections from multiple database
clients - Coordinates work into a single transaction
Server A
Database1
Connection
Server B
Database2
Connection
Transaction Management Using .NET Serviced
Components and COM Services
Page 7
8Introduction to Transaction Management
?
.NET Enterprise Services Transactions
- COM checks three bit flags to control
transaction outcome and component life time - Per object context Consistent flag and done
flag - Per transaction Abort flag
Transaction Stream
Sub1
Root Client
Root
Sub2
Abort
Transaction Management Using .NET Serviced
Components and COM Services
Page 8
9Overview of COM Services and the .NET Serviced
Components
- COM Services
- COM Catalog
- COM Context
- COM Interception
- How the .NET Framework Integrates with COM
Services - How the .NET Serviced Components Works with COM
Transaction Management Using .NET Serviced
Components and COM Services
10Overview of COM Services and the .NET Serviced
Components
COM Services
- COM is the application infrastructure in a
multi-user environment that compose of the
services that enable many users to access the
application and underlying data at the same time. - COM Services
- Transactions
- Compensating Resource Managers
- Resource Management
- Just-in-Time(JIT) Activation
- Object Pooling
- Synchronization
- Security
- Loosely Coupled Events
- Queued Components
Transaction Management Using .NET Serviced
Components and COM Services
Page 10
11Overview of COM Services and the .NET Serviced
Components
COM Catalog
- All configuration data is kept in a database
- You use the catalog to determine run-time
requirements when an object is activated - The catalog can be accessed by the Component
Services tool or administrative API
Catalog
Application Type Server Name
MyApp Component Name MyClass
Application MyApp
Class MyClass
Transaction Management Using .NET Serviced
Components and COM Services
Page 11
12Overview of COM Services and the .NET Serviced
Components
COM Context
- Context is a set of run-time requirements for a
class - The COM catalog stores run-time requirements as
attributes, which are checked during activation - Context properties flow with the method call,
depending on configuration attributes
Process
Application
Context A
Context B
Attributes TransactionRequired SynchronizationS
upported
Attributes TransactionRequired SynchronizationR
equiresNew
Object A
Object B
Properties TransactionID1234 ActivityID5678
Properties TransactionID1234 ActivityID9012
Transaction Management Using .NET Serviced
Components and COM Services
Page 12
13Overview of COM Services and the .NET Serviced
Components
COM Interception
- Used to enforce context semantics
- Transparent to the caller and the called
- Activation interception and method-call
interception
Client Process
Application
Context A
Context B
Synchronization Required
Synchronization Not Supported
Interception
Object A
Object B
Object C
Transaction Management Using .NET Serviced
Components and COM Services
Page 13
14Overview of COM Services and the .NET Serviced
Components
How the .NET Framework Integrates with COM
Services
- The System.EnterpriseServices namespace provides
necessary programming types - Activation and interception are handled
automatically through ServicedComponent class
.NET Enterprise Services
Common Language Runtime
COM Services
COM and Win32
Transaction Management Using .NET Serviced
Components and COM Services
Page 14
15Overview of COM Services and the .NET Serviced
Components
How the .NET Serviced Components Works with COM
Computer
COM Application Process
Context A
Context B
Interception
Object A objX
Object X
Proxy
objX new X ()
.NET Enterprise Services
COM Catalog
CoCreateInstance
CreateInstance
COM Services
Transaction Management Using .NET Serviced
Components and COM Services
Page 15
16Creating .NET Serviced Components
- Hosting Components in Component Services
- Transaction Attribute
- Transaction Voting
- Using the AutoComplete Attribute
- Setting Assembly Attributes
- Registering Assembly
- Monitoring COM Applications
- Demo Creating and Using StateU Serviced Component
Transaction Management Using .NET Serviced
Components and COM Services
17Creating .NET Serviced Components
Hosting Components in Component Services
- Add a reference to System.EnterpriseServices in
your assembly - The System.EnterpriseServices namespace provides
- ContextUtil class
- ServicedComponent class
- Assembly, class, and method attributes
- All component classes that need to be hosted
within a Component Services application must
inherit ServicedComponent class
Transaction Management Using .NET Serviced
Components and COM Services
Page 17
18Creating .NET Serviced Components
Transaction Attribute
- Transaction attributes specifies how a class
participates in transactions - Imports System.EnterpriseServices
- ltTransaction(TransactionOption.Required)gt Public
Class bizStateU - Inherits ServicedComponent
-
- End Class
- Options
- Disabled, NotSupported, Required, RequiresNew,
Supported
Transaction Management Using .NET Serviced
Components and COM Services
Page 18
19Creating .NET Serviced Components
Transaction Voting - 1
- ContextUtil class provides transaction voting
- Public Sub TransferClass()
- Try
-
- ContextUtil.SetComplete()
- Catch ex As Exception
- ContextUtil.SetAbort()
- Throw ex
- End Try
- End Sub
Transaction Management Using .NET Serviced
Components and COM Services
Page 19
20Creating .NET Serviced Components
Transaction Voting - 2
- Transaction Voting Options
- Transaction is terminated when Done bit of all
Context objects in transaction have True value
Transaction Management Using .NET Serviced
Components and COM Services
Page 20
21Creating .NET Serviced Components
?
Transaction Voting - 3
Transaction Stream
EnableCommit
SetComplete
Commit
CTrue DTrue
CTrue DFalse
SetComplete
Root Client
CTrue DTrue
SetComplete
CTrue DTrue
C Consistent Bit D Done Bit
Transaction Management Using .NET Serviced
Components and COM Services
Page 21
22Creating .NET Serviced Components
Using the AutoComplete Attribute
- AutoComplete attribute avoids using the SetAbort,
SetComplete, and ContextUtil methods - ltAutoComplete()gt Public Sub SetStateU(ByVal pSQL
As String) - Dim comStateU As New SqlCommand(pSQL,
conStateU) - comStateU.ExecuteNonQuery()
-
- ' not SetComplete or SetAbort is required
- End Sub
Transaction Management Using .NET Serviced
Components and COM Services
Page 22
23Creating .NET Serviced Components
Setting Assembly Attributes
- The information is stored in the AssemblyInfo.vb
file - ApplicationName
- Description
- ApplicationActivation
- AssemblyKeyFile
- Create key file using Strong Name Utility sn.exe
- sn.exe k StateU.snk
- ltAssembly ApplicationName("StateU")gt
- ltAssembly Description("State University Serviced
Component")gt - ltAssembly ApplicationActivation(ActivationOption.
Server)gt - ltAssembly AssemblyKeyFile("StateU.snk")gt
Transaction Management Using .NET Serviced
Components and COM Services
Page 23
24Creating .NET Serviced Components
Registering Assembly
- Manual Registration
- Using .NET Framework Services Installation
Utility Regsvcs.exe to register and create
Component Services application - Regsvcs.exe StateU.dll
- Automatic Registration
- Application registered on first use by client
Lazy Registration
Transaction Management Using .NET Serviced
Components and COM Services
Page 24
25Creating .NET Serviced Components
Monitoring COM Applications
Transaction Management Using .NET Serviced
Components and COM Services
Page 25
26Creating .NET Serviced Components
Demo Creating and Using StateU Serviced
Component
Transaction Management Using .NET Serviced
Components and COM Services
Page 26
27Please allow me to omit part of more details, as
it is too long to take up the subject in
full. For more information about COM Services,
go to Microsoft certified technical education
center and take the course below. 2557 Building
COM Applications Using Microsoft .NET
Enterprise Services
Transaction Management Using .NET Serviced
Components and COM Services
28QA
Biz doff_at_feelanet.com msn bpark_at_hanafos.com www.
feelanet.com www.forace.net www.wtime.net
Transaction Management Using .NET Serviced
Components and COM Services
29Thanks for your patience!