Firebird ADO.NET Provider SDK Documentation - v1.7

FbTransaction.Rollback Method (String)

Rolls back a transaction from a pending state, and specifies a savepoint name.

[Visual Basic]
Overloads Public Sub Rollback( _
   ByVal savePointName As String _
)
[C#]
public void Rollback(
   string savePointName
);

Parameters

savePointName
The savepoint name to which rollback changes.

Exceptions

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.

Example

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();
}        
                

See Also

FbTransaction Class | FirebirdSql.Data.Firebird Namespace | FbTransaction.Rollback Overload List