Begins a new transaction with the default isolation level IsolationLevel.ReadCommitted.
An FbTransaction object.
To commit or rollback the transaction, you must explicitly use the Commit or Rollback methods.
Exception Type | Condition |
---|---|
InvalidOperationException |
A transaction is currently active. Parallel transactions are not supported. Or the connection is not valid and Open. |
public void RunFirebirdTransaction(string connectionString) { FbConnection connection = new FbConnection(connectionString); connection.Open(); // Start a new transaction FbTransaction transaction = connection.BeginTransaction();; // Creates a new FbCommand object FbCommand command = new FbCommand(); command.Connection = connection; command.Transaction = transaction; try { command.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')"; command.ExecuteNonQuery(); command.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')"; command.ExecuteNonQuery(); transaction.Commit(); Console.WriteLine("Both records are written to database."); } catch(Exception e) { myTrans.Rollback(); Console.WriteLine(e.ToString()); Console.WriteLine("Neither record was written to database."); } finally { myConnection.Close(); } }
FbConnection Class | FirebirdSql.Data.Firebird Namespace | FbConnection.BeginTransaction Overload List