dotConnect for Oracle Documentation
Devart.Data.Oracle Namespace / OracleConnection Class / OracleLogicalTransaction Property
Example

OracleLogicalTransaction Property
Gets an OracleLogicalTransaction object, which allows you to determine whether the running transaction during the last database outage was successfully committed and completed.
Syntax
'Declaration
 
Public ReadOnly Property OracleLogicalTransaction As OracleLogicalTransaction
 

Property Value

A OracleLogicalTransaction object for OCI mode connection to Oracle 12c and higher. Null for OracleConnection.Direct mode connection or connection to Oracle with version lower than 12c.
Example
The following example demonstrates how to use the OracleLogicalTransaction class and its members in order to correctly process database outages and resubmit or rollback the last running transaction depending on its status.
using System;
using Devart.Data.Oracle;
 
class Test
{
        static void Main()
        {
                string constr = "User Id=Scott;Password=tiger;Data Source=Ora;";
                OracleConnection connection = new OracleConnection(constr);
                OracleTransaction transaction = null;
                OracleCommand command = null;
 
                try
                {
                        connection.Open();
                        transaction = connection.BeginTransaction();
                        command = new OracleCommand(connection, "update emp set dept=10 where empno=4321");
                        command.ExecuteNonQuery();
                }
                catch(Exception e)
                {
                        Console.WriteLine(e.ToString());
                        return;
                }
 
                try
                {
                        transaction.Commit();
                }
                catch(Exception e)
                {
                        if (e.IsRecoverable)
                        {
                                OracleLogicalTransaction logicalTransaction = connection.OracleLogicalTransaction;
                                logicalTransaction.GetOutcome(); // or logicalTransaction.GetOutcome("scott", "tiger", "inst1");
         
                                if (!logicalTransaction.Committed && !logicalTransaction.UserCallCompleted)
                                {
                                // any chosen processing here if a retry is desired.
                        }
                                else
                                {
                                // transaction committed, but was not full completed
                                }
                                }
                        else
                        {
                                // Not recoverable transaction. Rollback (and re-execute).
                        }
                }
        }
}
Imports Devart.Data.Oracle

Class Test
        Private Shared Sub Main()
                Dim constr As String = "User Id=Scott;Password=tiger;Data Source=Ora;"
                Dim connection As New OracleConnection(constr)
                Dim transaction As OracleTransaction = Nothing
                Dim command As OracleCommand = Nothing

                Try
                        connection.Open()
                        transaction = connection.BeginTransaction()
                        command = New OracleCommand(connection, "update emp set dept=10 where empno=4321")
                        command.ExecuteNonQuery()
                Catch e As Exception
                        Console.WriteLine(e.ToString())
                        Return
                End Try

                Try
                        transaction.Commit()
                Catch e As Exception
                        If e.IsRecoverable Then
                                Dim logicalTransaction As OracleLogicalTransaction = connection.OracleLogicalTransaction
                                logicalTransaction.GetOutcome()
                                ' or logicalTransaction.GetOutcome("scott", "tiger", "inst1");
                                ' any chosen processing here if a retry is desired.
                                If Not logicalTransaction.Committed AndAlso Not logicalTransaction.UserCallCompleted Then
                                        ' transaction committed, but was not full completed
                                Else
                                End If
                                ' Not recoverable transaction. Rollback (and re-execute).
                        Else
                        End If
                End Try
        End Sub
End Class
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also