Database Transactions in Business Central: Codeunit.Run, CommitBehavior & TryFunction

Опубликовано: 16 Июль 2026
на канале: Stefan Maron
382
14

Database transactions in Business Central are more subtle than they look. This stream works through the real behavior — building a small AL test extension and watching what actually commits and what gets rolled back, including some results that were genuinely surprising.

The biggest thing to understand: Codeunit.Run completes with an implicit commit at the end of its execution. That commit is independent of the calling transaction, so an error thrown after a Codeunit.Run call does not roll back what happened inside it. The CommitBehavior attribute helps suppress explicit Commit() calls, but it does not cover the implicit commit from Codeunit.Run. TryFunction adds another wrinkle — database writes behave differently in sandbox versus on-premise environments, which means code that works fine in development can blow up in a CI pipeline.

The stream also covers CurrentTransactionType and the five isolation levels available in AL (Browse, Snapshot, UpdateNoLocks, Update, Report), how to use Database.IsInWriteTransaction() defensively, and why auto-increment fields do not roll back even when a transaction is fully reverted.

Streaming all kinds of coding for Microsoft Dynamics 365 Business Central.
Join me to just hang out or tell me what I am doing wrong ;)

Join me live and let's build this together.

📝 Blog post: https://stefanmaron.com/posts/bc-data...

https://github.com/StefanMaron/Transa...

====== Content of this Video ======
0:00 - Introduction and setup
2:18 - Explaining transactions in Business Central
5:01 - Creating a basic lock table and list page
9:22 - Demonstrating basic transactions and errors
13:34 - Exploring commit behavior in transactions
21:19 - Discussing codeunit run behavior
34:35 - Examining error behavior and commit behavior
43:42 - Testing transactions in sandboxes vs on-premise
54:52 - Investigating try functions and rollback behavior
1:11:16 - Exploring transaction types and isolation levels
1:24:52 - Discussing when transactions start and default behaviors
1:27:54 - Conclusion and wrap-up

About Me:
https://stefanmaron.com/

Music by:
   / @streambeatsbyharrisheller  
https://open.spotify.com/artist/6GTRL...