Rolls back a transaction from a pending state, and specifies a savepoint name.
Exception Type | Condition |
---|---|
FbException | An error occurred while trying to rollback the transaction. |
InvalidOperationException | The transaction has already been committed or rolled back. |
InvalidOperationException | FbCommand is currently busy Open, Fetching. |
FbConnection myConnection = new FbConnection(connectionString); myConnection.Open(); FbCommand myCommand = new FbCommand(); FbTransaction myTrans; // Start a local transaction myTrans = myConnection.BeginTransaction(); // Assign transaction object for a pending local transaction myCommand.Connection = myConnection; myCommand.Transaction = myTrans; try { myCommand.CommandText = "INSERT INTO PROJECT(proj_id, proj_name, product) Values('FBNP', '.Net Provider', 'N/A')"; myCommand.ExecuteNonQuery(); myTrans.Save("SampleTransaction"); myCommand.CommandText = "INSERT INTO PROJECT(proj_id, proj_name, product) Values('FBN1', '.Net Provider1.', 'N/A')"; myCommand.ExecuteNonQuery(); myTrans.Commit(); Console.WriteLine("Both records are written to database."); } catch(Exception e) { try { myTrans.Rollback("SampleTransaction"); } catch (FbException ex) { if (myTrans.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 { myConnection.Close(); }
FbTransaction Class | FirebirdSql.Data.Firebird Namespace | FbTransaction.Rollback Overload List