Firebird ADO.NET Provider SDK Documentation - v1.7

FbConnection.BeginTransaction Method (String)

Begins a new transaction with the specified name.

[Visual Basic]
Overloads Public Function BeginTransaction( _
   ByVal transactionName As String _
) As FbTransaction
[C#]
public FbTransaction BeginTransaction(
   string transactionName
);

Parameters

transactionName
The name of the transaction.

Return Value

An FbTransaction object.

Remarks

To commit or rollback the transaction, you must explicitly use the Commit or Rollback methods.

Exceptions

Exception Type Condition
InvalidOperationException

A transaction is currently active. Parallel transactions are not supported.

Or the connection is not valid and Open.

Example

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

See Also

FbConnection Class | FirebirdSql.Data.Firebird Namespace | FbConnection.BeginTransaction Overload List