Problem with Transaction.TransactionCompleted event in OracleConnection
Hello,
My team is developing a persistence framework and we have had problem when we are using
the Transaction.TransactionCompleted Event. The problem occur when i use TransactionScope
and i want to do Rollback in transaction. When i use SqlConnection the event is fired
immediately after the transaction end scope, in other words synchronously. When i change my
connection to use Oracle.DataAccess.Client.OracleConnection the event isn't fired immediately
after the transaction end scope and others commands are executed until the event be executed
asynchronously.
To demostrate better the problem i did this test below.
In this example, when i use SqlConnection, the code firstly execute the assignment
to Divisor variable, which is in transaction_TransactionCompleted, and after it the division
operation is executed.
When i use OracleConnection, the program execute the division operation before the assignment
and one division by zero exception is thrown.
class Program
{
static int Divisor = 0;
static void Main(string[] args)
{
using (TransactionScope scope = new TransactionScope())
{
//Oracle
IDbConnection connection = new OracleConnection("Oracle ConectionString ");
//SqlServer
//IDbConnection connection = new SqlConnection("SqlServer ConectionString ");
connection.Open();
IDbCommand commandInsert = connection.CreateCommand();
commandInsert.CommandText = "INSERT INTO FC20.CATEGORIES (CATEGORYNAME) VALUES ('CATEGORIAxxxx')";
commandInsert.ExecuteNonQuery();
Transaction transaction = Transaction.Current;
transaction.TransactionCompleted += new TransactionCompletedEventHandler(transaction_TransactionCompleted);
connection.Close();
}
double Result = 10 / Divisor;
}
static void transaction_TransactionCompleted(object sender, TransactionEventArgs e)
{
Divisor = 1;
Console.Write("It´s OK.");
Console.ReadKey();
}
}
We 've been searching for solution in internet and we found a important information about System.Transactions and Promotable Transactions in Oracle in the following link: [http://download.oracle.com/docs/html/E15167_01/featADO20.htm]. Through this text was possible verify that in our scenario all transactions were promoted to distributed
transaction even when i did one only instance. So, the problem was resolved to local transactions scenarios when we put in ConnectionString the following configuration:
"Promotable Transaction=LOCAL" and the TransactionCompleted event come back to work synchronously.
My ODP version is 11.2.0.2.40 Beta included in Oracle Data Access Components (ODAC) for Microsoft Entity Framework and LINQ to Entities Beta 2.
I am using the Oracle DataBase 10g and the the ORM entity framework with .NET framework 4.0.
Now, my problem is how i do to TransactionCompleted event works synchronously when the transaction is realy distributed ?
Could someone help me about this question ?
Thank you for help.
Cristiano Gomes Franco
PETROBRAS - BRAZIL.