Error while accessing the database Cannot execute queries while other unbuffered queries are active

Hi,
i have a master detail form. in my detail form I added this code to onAfterInsert event:

//get all pallet numbers from all records in this form using RecID
sc_lookup(dataset,
"SELECT
PalletNumber
FROM
receivingdetails
WHERE
RecID = {RecID}");

$palletTotal = 0; //This variable holds the highest value of pallet number

for($i = 0; $i < count($dataset); $i++) //we loop based on number of array elements
{
//look for largest pallet number
if($dataset[i][0]>$palletTotal)
(
$palletTotal = $dataset[i][0]
);
}

sc_master_value('PalletTotal', $palletTotal);//update pallet total in master form

And this code gave me this error:

Error while accessing the database
Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.

I have another field that uses sql lookup and i disabled it. it didn’t work.
I still get the error even if the code is commented out or when i take out all code and sql statements.

So I imported my previous export that didn’t have any code and try to run my application and still get the same error even though this is an old version. I have no idea how to fix this.

I had this issue when a “;” were added or missing (I don’t remember).
So try to add a “;” in your SQL statement in your “sc_lookup()” like below

Blockquote
“SELECT
PalletNumber
FROM
receivingdetails
WHERE
RecID = {RecID};”);

Hi thanks for replying, I tried your suggestion and it worked But I went another direction because I asked support and they said to put sc_commit_trans(); at the end, so it’s resolved.