Firebird ADO.NET Provider SDK Documentation - v1.7

FbConnection.BeginTransaction Method (IsolationLevel)

Begins a new transaction with the specified isolation level.

[Visual Basic]
Overloads Public Function BeginTransaction( _
   ByVal level As IsolationLevel _
) As FbTransaction
[C#]
public FbTransaction BeginTransaction(
   IsolationLevel level
);

Parameters

level
The isolation level for 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();

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 Region (RegionID, RegionDescription) VALUES (100, 'Description')";
    command.ExecuteNonQuery();

    command.CommandText = "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')";
    command.ExecuteNonQuery();

    transaction.Commit();

    Console.WriteLine("Both records are written to database.");
}
catch(Exception e)
{
    transaction.Rollback();
    
    Console.WriteLine(e.ToString());
    Console.WriteLine("Neither record was written to database.");
}
finally
{
    connection.Close();
}
                

See Also

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