Row_CustomAction issue for MS SQL Server database

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
mobhar
User
Posts: 11703

Row_CustomAction issue for MS SQL Server database

Post by mobhar »

PHPMaker v2023.8.0.

I got the following error message when I was trying to run code in my Row_CustomAction server event:
/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/SQLSrv/Exception/Error.php(45): SQLSTATE [42000, 3988]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]New transaction is not allowed because there are other threads running in the session.

Code in Page_Load server event:

$this->CustomActions["terima_email_multi"] = new ListAction("terima_email_multi", "Toggle Receive Email", IsLoggedIn(), ACTION_POSTBACK, ACTION_MULTIPLE, "Toggle Receive Email for selected row(s)?", "fas fa-star ew-icon", "");

Code in Row_CustomAction server event:

if ($action == "terima_email_multi") { // Check action name
    if ($row["Terima_Email"] == "Y") {
         $rsnew = ["Terima_Email" => "N"]; // Array of field(s) to be updated
    } else {
         $rsnew = ["Terima_Email" => "Y"]; // Array of field(s) to be updated
    }
    $result = $this->update($rsnew, "ID_Pengguna = '" . $row["ID_Pengguna"] . "'"); // Update the current record only (the second argument is WHERE clause for UPDATE statement)
    if (!$result) { // Failure
        $this->setFailureMessage("Failed to update, Pengguna = " . $row["ID_Pengguna"]);
        return false; // Abort and rollback
    } elseif ($this->SelectedIndex == $this->SelectedCount) { // Last row
        $this->setSuccessMessage("All selected Pengguna have been successfully updated.");                
    }
    return true; // Success
}

arbei
User
Posts: 9359

Post by arbei »

You may disable transaction by Page_Load server event, e.g.

$this->UseTransaction = false;

mobhar
User
Posts: 11703

Post by mobhar »

Excellent. That did the trick. Thank you.


onoboa
User
Posts: 86
Location: Guayaquil - Ecuador

Post by onoboa »

I have the same problem with 2021v but when put this code, i got this error.

List_Page

function Page_Load()
{
//Log("Page Load");
$this->UseTransaction = false;
}

Undefined property: UseTransaction.


arbei
User
Posts: 9359

Post by arbei »

That means there was no such property in the old version. You need to customize the generated code yourself.


Post Reply