OracleLogicalTransaction Class
This class allows you to find out whether the transaction, running during the last database outage, was successfully committed and completed and determine whether your application should commit, complete, or rollback the transaction in order to avoid logical corruption because of committing duplicate transactions.
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(OracleException 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 fully 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 OracleException
If e.IsRecoverable Then
Dim logicalTransaction As OracleLogicalTransaction = connection.OracleLogicalTransaction
logicalTransaction.GetOutcome()
' or logicalTransaction.GetOutcome("scott", "tiger", "inst1");
If Not logicalTransaction.Committed AndAlso Not logicalTransaction.UserCallCompleted Then
' any chosen processing here if a retry is desired.
Else
' transaction committed, but was not fully completed
End If
Else
' Not recoverable transaction. Rollback (and re-execute).
End If
End Try
End Sub
End Class
System.Object
Devart.Data.Oracle.OracleLogicalTransaction
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