Begins a new transaction with the specified isolation level and transaction name.
An object representing the new transaction.
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. |
FbConnection connection = new FbConnection(connectionString); connection.Open(); // Start a new transaction FbTransaction transaction = myConnection.BeginTransaction(); // Creates a new FbCommand object FbCommand command = new FbCommand(); command.Connection = connection; command.Transaction = transaction; try { command.CommandText = "INSERT INTO PROJECT(proj_id, proj_name, product) Values('FBNP', '.Net Provider', 'N/A')"; command.ExecuteNonQuery(); transaction.Save("SampleTransaction"); command.CommandText = "INSERT INTO PROJECT(proj_id, proj_name, product) Values('FBN1', '.Net Provider1.', 'N/A')"; command.ExecuteNonQuery(); transaction.Commit(); Console.WriteLine("Both records are written to database."); } catch(Exception e) { try { transaction.Rollback("SampleTransaction"); } catch (FbException ex) { if (transaction.Connection != null) { Console.WriteLine("An exception of type " + ex.GetType() + " was encountered while attempting to roll back the transaction."); } } Console.WriteLine("An exception of type " + e.GetType() + " was encountered while inserting the data."); Console.WriteLine("Neither record was written to database."); } finally { connection.Close(); }
FbConnection Class | FirebirdSql.Data.Firebird Namespace | FbConnection.BeginTransaction Overload List