BeginTransaction

A wrapper for multiple SQL statements. Rolls back all SQL statements inside the transaction if one of the SQL statements returns an error or fails to execute.

This function creates a Transaction object in its execution path that can be used by the ExecuteSQL or ExecuteStoredProcedure functions. See the example below.

The transaction is committed automatically after all the functions in the execution path finished executing. If an error occurs inside the execution path, the transaction is rolled back.

Properties

Connection type

The type of database driver to use to connect to the database. The supported driver types are SQL Server, Oracle, OLE DB, and ODBC.

Connection string

The connection string that specifies how to connect to the database.

Isolation level

The isolation level for the transaction to use. The available options depend on the Connection type chosen.

Example

Suppose you have a variable containing an order with several line items that needs to be added to the database. Using ExecuteSQL without BeginTransaction would create a new database connection for each item written to the database. By using BeginTransaction, we can add everything in the same transaction. If something should go wrong during the creation of the order, the entire transaction would be rolled back, guaranteeing that we never end up having incomplete orders in the database. Adding many records using the same transaction will also execute a lot faster.

Set up the database connection on the BeginTransaction function. Then, for each ExecuteSQL, set the 'Connection type' property to Use transaction, and set the 'Transaction' property to 'BeginTransaction.Transaction'.

Begin Transaction Example