Page 1 of 1

Row_CustomAction issue for MS SQL Server database

Posted: Tue Dec 06, 2022 7:33 pm
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
}

Re: Row_CustomAction issue for MS SQL Server database

Posted: Wed Dec 07, 2022 9:55 am
by arbei

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

$this->UseTransaction = false;

Re: Row_CustomAction issue for MS SQL Server database

Posted: Wed Dec 07, 2022 10:00 am
by mobhar

Excellent. That did the trick. Thank you.


Re: Row_CustomAction issue for MS SQL Server database

Posted: Fri Feb 17, 2023 8:19 am
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.


Re: Row_CustomAction issue for MS SQL Server database

Posted: Fri Feb 17, 2023 10:36 am
by arbei

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