MySQL · Types · Services and connections

ArxTransaction

Definition

Namespace
ARX.SDK.Services
Package
ARX.SDK
C#
public abstract class ArxTransaction : IAsyncDisposable

A database transaction that ARX calls run in. Pass it to a service call, then CommitAsync or RollbackAsync. Disposing it without committing rolls it back.

Properties

  • ArxTransactionState State { get; }

    The transaction's state: Active until it is committed or rolled back. An aborted transaction (IsAborted) is still Active, because it is open and must still be rolled back; check IsAborted to know whether it can commit.

  • bool IsAborted { get; }

    True once a call in it failed at the database: it can only be rolled back.

Methods

  • Task CommitAsync(CancellationToken cancellationToken = default)

    Commits everything written in the transaction. On an aborted transaction it rolls back and throws ARX1015. If the database refuses the commit (for example a deferred constraint or a serialization failure), the mapped error is thrown and the state is RolledBack. If the connection fails or times out before the database answers (ARX7005, ARX7003, or a network error), the outcome is unknown: the state is OutcomeUnknown and the error thrown says so, with IsTransient false, so retry code doesn't run the work a second time unchecked. A token cancelled before the commit starts rolls back; the commit itself isn't cancelled, because stopping it half way would leave its outcome unknown.

    Parameter Type Description
    cancellationTokenCancellationToken= defaultCancels the call.
  • Task RollbackAsync(CancellationToken cancellationToken = default)

    Rolls back everything written in the transaction. Does nothing if it is already rolled back; fails with ARX1010 if it was committed. The rollback itself isn't cancelled.

    Parameter Type Description
    cancellationTokenCancellationToken= defaultCancels the call.
  • ValueTask DisposeAsync()

    Rolls back an active transaction, then releases it. Never throws for a failed rollback.

  • static Task<ArxTransaction> BeginOnOwnConnectionAsync(ArxConnection connection, CancellationToken cancellationToken = default)

    For the providers' IArxDataService.BeginTransactionAsync: begins a transaction on connection, which the transaction then owns and closes when it is disposed. The connection is closed at once if the transaction can't begin.

    Parameter Type Description
    connectionArxConnectionA new connection of the provider's own type, for this transaction only.
    cancellationTokenCancellationToken= defaultCancels the call.

Notes

ARX tracks what happened to it. A call that fails at the database aborts the transaction (IsAborted): later calls fail with ARX1015 before reaching the database, and CommitAsync rolls back and throws ARX1015 instead of appearing to commit. Some databases discard the transaction's work on any error (PostgreSQL); others undo only the failed statement (SQL Server, MySQL), so committing the rest would write only part of what the code meant: ARX rolls back on every provider, so a failed call never leaves a half-done unit of work. A call that fails validation (before the database) leaves the transaction usable. These rules live here, so every provider behaves the same; a provider supplies only the database work.