none
Why does the Transaction.TransactionCompleted Event have a different behavior with the use in Oracle.DataAccess.Client.OracleConnection and System.Data.SqlClient.SqlConnection ? RRS feed

  • Question

  • 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();
    }
    }



    I would like that the transaction.TransactionCompleted was fired synchronously in OracleConnection
    like occur in SqlConnection. Could someone help me about this question ?


    Thank you for help.

    Thursday, October 27, 2011 2:29 PM

All replies

  • Hi Cristiano,

    Welcome!

    I'm not sure about Orace database and provider, you can refer this link: https://forums.oracle.com/forums/thread.jspa?messageID=4127323, I think the problem relates to database, you can repost your question at : https://forums.oracle.com

    Thanks for understanding.

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, October 28, 2011 6:48 AM
    Moderator
  • Hi Alan,

    I 've seen this link but i think that it doesn't resolve the problem. 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.

    We were searching for solution in internet and we found a important text about the way like Oracle work with System.Transaction. Through this text was possible correct the problem to Local Transaction because we put in ConnectionString the following configuration "Promotable Transaction=LOCAL"  and  the TransactionCompleted event come back to work synchronously.

    Now, my problem is how i do to TransactionCompleted event works synchronously when the transaction is distributed ?

    We found information about System.Transactions and Promotable Transactions in Oracle in the following link: http://download.oracle.com/docs/html/E15167_01/featADO20.htm

     

    Thanks for help.

    Have a nice day.

    Tuesday, November 1, 2011 12:07 PM
  • Hi Cristiano,

    Thanks for your feedback.

    To tell you truth, I'm not familiar with the provider for Oracle. I'd like to redirect you to Oracle Forums for better support. Thanks for understanding!

    Have a nice day.


    Alan Chen[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Thursday, November 3, 2011 7:36 AM
    Moderator