IsloationLevel -Maximize Performance??
Senthil Kumar Varatharajan
Manager – D365 BC Technical Business Central at Mercurius IT| Microsoft Dynamics & SAP Solutions for better business | A safe pair of hands
In earlier versions of Microsoft Dynamics Business Central (BC), we often used methods like
Rec.LockTable(True),
Rec.Findset(True),
Rec.Findfirst()
Commit();
These methods frequently caused performance issues and bugs, especially with rollbacks. BC 23 introduces a new syntax:
Rec.ReadIsolation := IsolationLevel::<enum>,
which enhances performance and transaction control.
What are Isolation Levels?
Isolation levels help manage how data is read and locked during transactions. BC 23 provides several levels:
Examples
Counting Committed Records
Use ReadCommitted to count only committed records:
local procedure GetCommittedRecordCount(): Integer
var
GLEntry: Record "G/L Entry";
begin
GLEntry.ReadIsolation := IsolationLevel::ReadCommitted;
exit(GLEntry.Count());
end;
Counting Uncommitted Records
Use ReadUncommitted to include uncommitted changes in the count:
local procedure GetEstimatedCount(TableNo: Integer): Integer
var
RRef: RecordRef;
begin
RRef.Open(TableNo);
RRef.ReadIsolation := IsolationLevel::ReadUncommitted;
exit(RRef.Count());
end;
Getting the Next Entry Number
Use UpdLock to safely get the next entry number:
local procedure GetNextEntryNo(): Integer
var
GLEntry: Record "G/L Entry";
begin
GLEntry.ReadIsolation := IsolationLevel::UpdLock;
GLEntry.FindLast();
exit(GLEntry."Entry No." + 1);
end;
By using these new isolation levels in BC 23, you can improve performance and ensure more reliable transaction handling in your Business Central applications.
Henry Verheij