Skip to main content
Skip table of contents

Database transactions

Database structure

In Link 3 all data is divided into three databases:

  • Configuration

  • Transactional

  • BackupFiles

The Configuration database holds configuration data such as partners, distributions and all the developer objects. Whereas the Transactional and BackupFiles databases holds data generated by the flow such as interchanges, documents and their associated raw files.

Although these entities are related across databases by id’s, there are NO database constraints enforcing the data consistency.

Transactions

In many cases when updating multiple entities, it makes sense to join these updates in a database transaction. This gives you the possibility to roll back ALL changes if one of them fails.

To make things easier Link 3 provides a factory called ITransactionScopeFactory that can be dependency injected into your class.

Example: Using transaction scopes

In the example below we update multiple entities in the Configuration database. If an exception occurs the changes are automatically rolled back.

C#
using (var scope = transactionScopeFactory.CreateScope())
{
    try
    {
        //Updates to configuration data
        scope.Complete();
    }
    catch (Exception ex)
    {
        logger.LogError(ex, $"Exception occured: {ex.Message}");
    }
}

Example: Using transaction scopes across databases.

Transactions that consists of updates to or just accesses multiple databases are called distributed transactions. Unfortunately these types of transactions are not supported and would result in a PlatformNotSupportedException.

However it is possible to “break out” of a scope by using the method RunOutsideTransaction as seen in line 7 in the example below:

C#
using (var scope = transactionScopeFactory.CreateScope())
{
    try
    {
        //Updates to configuration data

        await transactionScopeFactory.RunOutsideTransaction(() =>
        {
            //Updates to transactional data
        });

        scope.Complete();
    }
    catch (Exception ex)
    {
        logger.LogError(ex, $"Exception occured: {ex.Message}");
    }
}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.