Begins a new transaction with the specified isolation level.
An FbTransaction object.
To commit or rollback the transaction, you must explicitly use the Commit or Rollback methods.
| Exception Type | Condition |
|---|---|
| InvalidOperationException |
A transaction is currently active. Parallel transactions are not supported. Or the connection is not valid and Open. |
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();
}
FbConnection Class | FirebirdSql.Data.Firebird Namespace | FbConnection.BeginTransaction Overload List