# BeginTransaction

This function creates a Transaction in its execution path that can be used by the SQLite [ExecuteSQL](/reference/plugins/sqlite/content/executesql.md) function.

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

If an error occurs, all SQL statements within the transaction are rolled back.

## Properties

### Connection string

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

### Isolation level

Controls when SQLite acquires locks on the database file. The three options map directly to SQLite's native `BEGIN` variants. [Learn more](https://www.sqlite.org/isolation.html)

{% hint style="info" %}
**Note**

Standard isolation levels such as Read Committed and Serializable are not supported by SQLite and are not exposed by this plugin.
{% endhint %}

| Isolation Level        | Lock acquired                        | Other connections can read | Other connections can write              |
| ---------------------- | ------------------------------------ | -------------------------- | ---------------------------------------- |
| **Deferred** (Default) | On first read or write               | :white\_check\_mark:       | :white\_check\_mark: (until first write) |
| **Immediate**          | On transaction open (write lock)     | :white\_check\_mark:       | :x:                                      |
| **Exclusive**          | On transaction open (exclusive lock) | :x:                        | :x:                                      |

***

## Example

Suppose you have a sales order with multiple line items that need to be added to the database.

Using [ExecuteSQL](/reference/plugins/sqlite/content/executesql.md) *without* **BeginTransaction** creates a new database connection for each item written. By using **BeginTransaction**, all items are added within the same transaction.

If an error occurs during order creation, the entire transaction is rolled back, ensuring no incomplete orders are stored in the database. Adding multiple records within the same transaction also significantly improves execution speed.

**Steps:**

1. Add a **BeginTransaction** function to your Solution.
2. Configure the **Connection string**.
3. Add your **ExecuteSQL** functions to your workflow.
4. For each **ExecuteSQL**, select the *Use transaction* property.
5. Set the *Transaction* property (only displayed when *Use transaction* is selected) to 'BeginTransaction.Transaction'.

<div align="left"><img src="/files/1TfjlA9noTcTfDFi3zzg" alt="Example of BeginTransaction"></div>

## Links

* [Wikipedia: Database transaction](https://en.wikipedia.org/wiki/Database_transaction)
* [SQLite: Isolation in SQLite](https://www.sqlite.org/isolation.html)


---

# 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/sqlite/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.
