# BeginTransaction

### BeginTransaction <a href="#begintransaction" id="begintransaction"></a>

The **BeginTransaction** function serves as a wrapper for multiple SQL statements.

This function creates a Transaction object in its execution path that can be used by the [ExecuteSQL](/reference/plugins/database/content/executesql-function.md) or [ExecuteStoredProcedure](/reference/plugins/database/content/execute-stored-procedure.md) functions.

The transaction is committed automatically after all the functions in the execution path finished executing.

If one of the SQL statements returns an error or fails to execute, all SQL statements inside the transaction are rolled back.

***

### Properties <a href="#properties" id="properties"></a>

#### Connection type <a href="#connection-type" id="connection-type"></a>

The type of database driver to use to connect to the database.

The supported driver types are:

* SQL Server
* Oracle
* OLE DB
* ODBC

#### Connection string <a href="#connection-string" id="connection-string"></a>

The [connection string ](/reference/plugins/database/shared-properties/connectioneditor.md)that specifies how to connect to the database.

#### Isolation level <a href="#isolation-level" id="isolation-level"></a>

The isolation level for the transaction. [learn more](https://en.wikipedia.org/wiki/Isolation_\(database_systems\))

The available options depend on the *Connection type* that was selected.

| Isolation level  | Connection type                          |
| ---------------- | ---------------------------------------- |
| Chaos            | OLE DB                                   |
| Read committed   | OLE DB, SQL Server, Oracle, OLE DB, ODBC |
| Read uncommitted | SQL Server, OLE DB, ODBC                 |
| Repeatable read  | SQL Server, OLE DB, ODBC                 |
| Serializable     | SQL Server, Oracle, OLE DB, ODBC         |

***

### Example <a href="#example" id="example"></a>

Suppose you have a sales order containing several line items that must be added to the database.

Using [ExecuteSQL ](/reference/plugins/database/content/executesql-function.md)*without* **BeginTransaction** would create a new database connection for each item written to the database. However, 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.

**Steps:**

1. Add a **BeginTransaction** function to your Solution.
2. Set up the database connection for the **BeginTransaction** function.
3. Add your **ExecuteSQL** functions to your work flow.
4. For each **ExecuteSQL**, set the *Connection type* property to 'Use transaction'.
5. Set the *Transaction* property (only displayed when *Connection type* property is 'Use transaction') to 'BeginTransaction.Transaction'.

<div align="left"><figure><img src="/files/OfMaUTQFhkM6P10AMQA0" alt=""><figcaption></figcaption></figure></div>

***

### Links <a href="#links" id="links"></a>

[Wikipedia: Database transaction](https://en.wikipedia.org/wiki/Database_transaction)

[Wikipedia: Isolation (database systems)](https://en.wikipedia.org/wiki/Isolation_\(database_systems\))


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.linx.software/reference/plugins/database/content/begintransaction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
