In Oracle-compatible mode, OceanBase Connector/NET provides the OracleConnection.AutoCommit property, which is aligned with ODP.NET AutoCommit.
Connection String and Runtime Properties
Concepts |
Description |
|---|---|
Connection StringAutoCommit |
Initial Default Value (Defaulttrue) and is restored to this value when the connection pool is reset. |
OracleConnection.AutoCommit |
Current Session Value: Can be set before and after opening a connection. |
Note
If the application does not set runtime properties, its behavior will be consistent with older versions configured only via the connection string, and this does not constitute a compatibility change.
Recommended Usage (Connection string defaults to AutoCommit=true)
TransactionScope.Suppress + Regular DML + ArrayBinding
// Connection string: AutoCommit=true (default), UseArrayBinding=true
using (var scope = new TransactionScope(TransactionScopeOption.Suppress))
{
using var conn = new OracleConnection(connStr);
conn.Open();
AuditInsert(conn); // Normal DML: auto-commit
conn.AutoCommit = false; // Set after connecting to meet the prerequisite for ArrayBinding.
ArrayBindInsert(conn);
conn.AutoCommit = true; // Required: Commit the batch and restore automatic commit.
scope.Complete();
}
Reasons for Explicit Recovery or Commit: Regular DML and batch operations generated while AutoCommit=false are uncommitted will be rolled back when the connection is closed. When using the runtime switching method above, setting conn.AutoCommit back to true will first commit the implicit transaction and then restore automatic commit.
Single Primary Table Row + Detail ArrayBinding (No Requirement for Same DB Transaction)
conn.Open(); // Connection string AutoCommit=true
UpdateMainTable(conn); // Single UPDATE, already automatically committed
conn.AutoCommit = false;
ArrayBindDetailRows(conn);
conn.AutoCommit = true; // Commit detail batch
Primary Table + Detail in Same DB Transaction
conn.AutoCommit = false; // Must be done before BeginTransaction
using (var tx = conn.BeginTransaction())
{
UpdateMainTable(conn, tx);
ArrayBindDetailRows(conn, tx);
tx.Commit();
}
conn.AutoCommit = true;
Summary of Property Semantics
Action |
Behavior |
|---|---|
After the connection is established, set it tofalse |
ExecuteSET autocommit=0 |
After the connection is established, set it totrue |
When no explicit local transaction is present, an implicit transaction is first committed, and then the operation is executed.SET autocommit=1 |
| Explicit transaction end | ViaCommit()orRollback()Restore the AutoCommit value before the transaction started after the transaction is ended. |
Distributed transactions are registered or active.OracleTransactionSet at |
Thrown WhenInvalidOperationException |
Common misconceptions
Misunderstanding |
actual |
|---|---|
AutoCommitCan only be set before opening a connection |
ODP.NET semantics allow setting this after the connection is opened. |
scope.Complete()Alternative Database Commit |
Complete()Only marks the success of an environment transaction and cannot replace a driver-side commit. |
ArrayBinding must be set in the connection string.AutoCommit=false |
It is only required that the current session has autocommit=0; this setting can also be configured at runtime.conn.AutoCommit=false |
BeginTransaction()Alternative session autocommit=0 |
No; the driver will refuse to execute, and under legacy behavior, you may also receive a server-side error.-4007Error |
