This document describes the PX1042 diagnostic.
Code | Short Description | Type | Code Fix |
---|---|---|---|
PX1042 | In a RowSelecting handler, BQL statements and other database queries must be executed only inside a separate connection scope. For Acumatica ERP 2023 R1 and later versions, this diagnostic is disabled. |
Error | Available |
In a RowSelecting
handler, BQL statements and other database queries (such as PXDatabase.Select
) must be executed only inside a separate connection scope.
The use of a separate connection scope is required to execute additional BQL statements in
the RowSelecting
event handler, because the current connection scope used to retrieve data is
still busy at the moment. Thus no other operations on this connection scope are allowed.
Starting with Acumatica ERP 2023 R1, the Acumatica runtime was changed to allow DB queries execution in the RowSelecting
event handler without a separate connection scope. Therefore, for Acumatica ERP 2023 R1, this diagnostic is disabled.
The code fix surrounds the BQL statement or the database query execution with a connection scope.
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
protected virtual void _(Events.RowSelecting<SOOrder> e)
{
var setup = PXSelect<SOSetup>.SelectSingleBound(Base, null); // The PX1042 error is displayed for this line.
}
}
public class SOOrderEntryExt : PXGraphExtension<SOOrderEntry>
{
protected virtual void _(Events.RowSelecting<SOOrder> e)
{
using (new PXConnectionScope())
{
var setup = PXSelect<SOSetup>.SelectSingleBound(Base, null);
}
}
}