2 Using the Data Providers : Using Transactions

Using Transactions
All DataDirect Connect for ADO.NET data providers support both local and distributed transactions.
System.Transactions
The System.Transactions namespace contains classes to allow you to write a transactional application using only managed code. In the infrastructure provided in System.Transactions is a grouping that allows more inclusive and efficient transactional programming. Transaction behavior can be controlled directly using the Transaction class or implicitly using the TransactionScope class.
We recommend using the System.Transactions objects for all transaction processing with the DataDirect Connect for ADO.NET data providers.
Using Local Transactions
All DataDirect Connect for ADO.NET data providers use 100% managed code in supporting local transactions. Local transactions are implemented within the .NET Framework. A local transaction uses the internal transaction manager of the underlying database.
If your application connects to only one database and you have no requirement to connect to another database, use local transactions, as shown in Figure 2-2. Local transactions are always faster than distributed transactions, which require additional logging and network round trips. In addition, local transactions provide the added benefit of increased security because the data provider does not need to call unmanaged code.
Figure 2-2. Using Local Transactions in the .NET EnvironmentThe .NET object connects to the ADO.NET data provider inside the .NET Framework. The data provider then connects to the database. No unmanaged code is involved.
 
Using Distributed Transactions
The DataDirect Connect for ADO.NET data providers support distributed transactions only when the application is written to serviced components. For a general discussion of using serviced components, refer to the Microsoft ADO.NET Framework SDK documentation.
The DataDirect Connect for ADO.NET data providers support distributed transactions using the Microsoft Distributed Transaction Coordinator (MS DTC), which is provided through System.Transactions. You must include specific code, such as System.Transaction, in the namespace of your application.
The MS DTC service must be in a running state. On the MSDTC tab of the Component Services Administrative ToolSet, specify the Security Configuration setting:
NOTE: The location of the MS DTC configuration varies by Windows version. Refer to the Microsoft Windows help for detailed information for your environment.
Figure 2-3 illustrates using a distributed transaction.
Figure 2-3. Using Distributed Transactions in the .NET Environment.NET objects connect to ADO.NET data providers, which communicate to MS DTC outside the .NET Framework, and then to the Oracle and Sybase databases.
 
Distributed transactions are significantly slower than normal transactions due to the logging and network round trips necessary to communicate between all the components involved in the distributed transaction.
Because the DataDirect Connect for ADO.NET data providers are managed data providers, you can still enjoy some of the benefits of the .NET Framework security when you use distributed transactions. The security afforded by the data provider, with the security defined in the database, provides good protection when you use distributed transactions.
See “Handling Dead Connections in a Pool” for information about how connections used in a distributed transaction are processed in a connection pool.