Row_CustomAction issue for MS SQL Server database
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
}