Establish a new Save point for the current transaction with the given name.
Savepoints offer a mechanism to roll back portions of transactions. You create a savepoint using the Save method, and then later call the Rollback method to roll back to the savepoint instead of rolling back to the start of the transaction.
Exception Type | Condition |
---|---|
FbException | An error occurred while trying to commit 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