Đang chuẩn bị liên kết để tải về tài liệu:
Creating a Class That Participates in an Automatic Transaction

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

[ Team LiB ] Recipe 6.1 Creating a Class That Participates in an Automatic Transaction Problem You need to create a .NET class that participates in automatic transactions. Solution Use the appropriate custom attributes from the System.EnterpriseServices namespace. | Team LiB Recipe 6.1 Creating a Class That Participates in an Automatic Transaction Problem You need to create a .NET class that participates in automatic transactions. Solution Use the appropriate custom attributes from the System.EnterpriseServices namespace. The sample contains a component that participates in automatic transactions. The component has a single method TranTest that instructs the transaction to succeed or fail based on an argument success. The sample also contains code that instantiates the component that participates in the automatic transaction. A checkbox on the form is used to specify the success parameter when the TranTest method is called. The C code is shown in Examples Example 6-1 and Example 6-2. Example 6-1. ServicedComponentCS Project File SC0601.cs Namespaces variables and constants using System.EnterpriseServices using System.Runtime.CompilerServices using System.Reflection . . . namespace AdoDotNetCookbookCS.ServicedComponentCS Transaction TransactionOption.Required public class SC0601 ServicedComponent AutoComplete public void TranTest bool success . . . Do some work. if success II don t need the next line since AutoComplete ContextUtil.SetComplete else II Vote to abort. ContextUtil.SetAbort II Raise an exception. throw new System.Exception Error in Serviced Component 0601. Transaction aborted. Example 6-2. File AutoTransactionForm.es II Namespaces variables and constants using System using System.Windows.Forms using AdoDotNetCookbookCS.ServicedComponentCS II . . . SC0601 sc new SC0601 try sc.TranTest transactionSucceedCheckBox.Checked MessageBox.Show Transaction successful. Automatic Transactions MessageBoxButtons.OK MessageBoxIcon.Information catch Exception ex MessageBox.Show ex.Message Automatic Transactions MessageBoxButtons.OK MessageBoxIcon.Error Discussion The .NET Common Language Runtime CLR supports both manual and automatic transaction models. The automatic distributed transaction model supported by the .NET CLR is the .