プライマリ・コンテンツに移動
Oracle® Data Provider for .NET開発者ガイド
ODAC 12.2c リリース1 (12.2.0.1) for Microsoft Windows
E88311-03
目次へ移動
目次
索引へ移動
索引

前
次

EnlistDistributedTransaction

このメソッドにより、アプリケーションは接続がオープンされた後に特定の分散トランザクションに明示的に登録できます。

宣言

// C#
public void EnlistDistributedTransaction(ITransaction transaction);

パラメータ

  • transaction

    ITransactionインタフェース。

例外

InvalidOperationException - 接続がローカル・トランザクションの一部であるか、または接続がクローズされています。

備考

EnlistDistributedTransactionにより、メソッドに渡された特定のトランザクションにオブジェクトを登録できます。ITransactionインタフェースは、分散トランザクションを開始したコンポーネント内でContexUtil.Transactionプロパティに(ITransaction)キャストを適用することで取得できます。

このメソッドを呼び出す前に接続がオープンされている必要があります。そうしないとInvalidOperationExceptionがスローされます。

接続が、分散トランザクションに登録を試みている最中に暗黙的または明示的に開始されたローカル・トランザクションの一部である場合、ローカル・トランザクションはロールバックされ、例外がスローされます。

デフォルトでは、メソッド・レベルのAutoComplete宣言が設定されていないかぎり、分散トランザクションはロールバックされます。

ITranasctionに対してコミットを起動すると例外が発生します。

ITransactionメソッドに対してロールバックを起動し、同一分散トランザクションに対してContextUtil.SetCompleteを呼び出すと、例外が発生します。

備考(.NETストアド・プロシージャ)

このメソッドを使用すると、未サポートの例外が発生します。

アプリケーション:

// C#
 
/* This is the class that will utilize the Enterprise Services 
   component.  This module needs to be built as an executable.
   
   The Enterprise Services Component DLL must be built first 
   before building this module. 
   In addition, the DLL needs to be referenced appropriately 
   when building this application. 
*/
 
using System;
using System.EnterpriseServices;
using DistribTxnSample;
 
class DistribTxnSample_App
{
  static void Main()
  {
    DistribTxnSample_Comp comp = new DistribTxnSample_Comp();
    comp.DoWork();
  }
}

コンポーネント:

// C#
 
/* This module needs to be
   1) built as a component DLL/Library
   2) built with a strong name
   
  This library must be built first before the application is built.
*/ 
 
using System;
using System.Data;
using Oracle.DataAccess.Client; 
using System.EnterpriseServices;
 
namespace DistribTxnSample
{
  [Transaction(TransactionOption.RequiresNew)]
  public class DistribTxnSample_Comp : ServicedComponent
  {
    public void DoWork()
    {   
      string constr = 
        "User Id=scott;Password=tiger;Data Source=oracle;enlist=false";
      OracleConnection con = new OracleConnection(constr);
      con.Open();
 
      // Enlist in a distrubuted transaction
      con.EnlistDistributedTransaction((ITransaction)ContextUtil.Transaction);
 
      // Update EMP table
      OracleCommand cmd = con.CreateCommand();
      cmd.CommandText = "UPDATE emp set sal = sal + .01";
      cmd.ExecuteNonQuery();
 
      // Commit
      ContextUtil.SetComplete();
 
      // Dispose OracleConnection object
      con.Dispose();
    }
  }
}