I’ve got something that is seeming to fail on 2026.1 custom BPM code. I’ve got multiple examples where I’ve got reads of a database table within a foreach loop of other reads, and it’s throwing an error “There is already an open DataReader associated with this Connection which must be closed first.” on the app server log.
This example, I’m reading through PORel records, and in that loop, I’m reading the TranGLC looking for the first GL Account.
foreach(var ord in ( from rrow in Db.PORel
where rrow.Company == wkCompany
&& rrow.PONum == wkPONum
&& rrow.TranType == "PUR-UKN"
select new { rrow.PONum, rrow.POLine, rrow.PORelNum } ))
{
xPONum = ord.PONum.ToString();
xPOLine = ord.POLine.ToString();
xPORelNum = ord.PORelNum.ToString();
var gl = ( from grow in Db.TranGLC
where grow.Company == wkCompany
&& grow.RelatedToFile == "PORel"
&& grow.Key1 == xPONum
&& grow.Key2 == xPOLine
&& grow.Key3 == xPORelNum
select new { grow.GLAccount } ).FirstOrDefault();
if (gl == null ) HANDLE NO ACCOUNT HERE
else PROCESS ACCOUNT HERE
}
When I execute this code, I get the “open datareader” error. However, if I move the read of TranGLC outside the foreach read of PORel - it executes cleanly.
foreach(var ord in ( from rrow in Db.PORel
where rrow.Company == wkCompany
&& rrow.PONum == wkPONum
&& rrow.TranType == "PUR-UKN"
select new { rrow.PONum, rrow.POLine, rrow.PORelNum } ))
{
xPONum = ord.PONum.ToString();
xPOLine = ord.POLine.ToString();
xPORelNum = ord.PORelNum.ToString();
}
var gl = ( from grow in Db.TranGLC
where grow.Company == wkCompany
&& grow.RelatedToFile == "PORel"
&& grow.Key1 == xPONum
&& grow.Key2 == xPOLine
&& grow.Key3 == xPORelNum
select new { grow.GLAccount } ).FirstOrDefault();
if (gl == null ) HANDLE NO ACCOUNT HERE
else PROCESS ACCOUNT HERE
Obviously, when it’s outside the loop, it’s only checking the last PORel record instead of processing each one.
This isn’t the only place I’m getting this error. I’m getting it on other BPM custom code, haven’t fully tested that but in that BPM also, I’m reading through one table doing processing, and eventually trying to read additional tables.