Transactions C# Help

Automatic transactions are the most frequently used feature of Enterprise Services. Using Enterprise Services, you can mark the components as requiring a transaction, and the transaction is then created from the COM+ runtime. All transaction-aware objects inside the component, such as ASP.NET connections, run inside the transaction.

You can read more about the concepts of transactions in Chapter 22, “Transactions.”

Transaction Attributes

Serviced components can be marked with the [Transaction] attribute to define if and how transactions are required for the component.

Figure 44-6 shows multiple components with different transactional configurations. The client invokes component A. Because component A is configured with Transaction Required and no transaction existed previously, the new transaction, 1, is created. Component A invokes component B, which in turn invokes component C. Because component B is configured with Transaction Supported, and the configuration of component C is set to Transaction Required, all three components (A, B, and C) do use the same transaction context. If component B were configured with the transaction setting Not Supported, component C would get a new transaction. Component D is configured with the setting New Transaction Required, so a new transaction is created when it is called by component A.

The following table lists the different values that you can set with the Transaction Option enumeration:

Figure 44-6

Figure 44-6

TransactIon Results

A transaction can be influenced by setting the consistent and the done bit of the context. If the consistent bit is set to true, the component is happy with the outcome of the transaction. The transaction can be committed if all components participating with the transaction are similarly successful. If the consistent bit is set to false, the component is not happy with the outcome of the transaction, and the transaction will be aborted when the root object that started the transaction is finished. If the done bit is set, the object can be deactivated after the method call ends. A new  Instance will be created with the next method call.

The consistent-and done bits can be set using four methods of the Context Util class with the results  that you can see in the following table.

With .NET it is also possible to set the consistent and done bit by applying the attribute [Autocomplete] to the method instead of calling the ContextUtil methods. With this attribute the method ContextUtil. SetComplete() will be called automatically if the method is successful. If the method fails and an exception is thrown, with [AutoComplete] the method Cont.extUtil. SetAbort() will be called.

Posted on October 31, 2015 in Enterprise Services

Share the Story

Back to Top
Share This