Unable to cancel a query in DB2 - stored-procedures

I have the following stored procedure in DB2:
CREATE OR REPLACE PROCEDURE CANCEL_ACTIVITY (IN application_handle INTEGER)
LANGUAGE SQL
BEGIN
DECLARE UOW_ID INTEGER;
DECLARE ACTIVITY_ID INTEGER;
FOR v AS cur1 CURSOR FOR
SELECT UOW_ID, ACTIVITY_ID FROM TABLE(SYSPROC.MON_GET_ACTIVITY(application_handle, -1))
DO
CALL WLM_CANCEL_ACTIVITY(application_handle, v.uow_id, v.activity_id);
END FOR ;
END
Using the following query, I am able to find my connection ID:
SELECT MON_GET_APPLICATION_HANDLE() from SYSIBM.SYSDUMMY1
Which would return a value like 36547. So I call the procedure I just created like so:
CALL CANCEL_ACTIVITY(36547);
As a result, I get the following:
However, if I execute the query that gets connection IDs again, it doesn't seem like that connection ID is gone. I still get the 36547 value returned.
I am quite confused whether this query canceling is working at all. I am getting a range of different type of errors in different environments I am executing the code at.
When I am running it as a SQL query, I get the above error code / response. When my code is being executed in my webpage, I get the following error:
Cannot cancel queries: Java::ComIbmDb2JccAm::SqlDataException: DB2 SQL Error: SQLCODE=-802, SQLSTATE=22003, SQLERRMC=null, DRIVER=4.16.53
I am curious what I am doing wrong?

I would recommend to read Canceling Activies in the DB2 documentation. Canceling an activity is not closing a connection, but selectively aborting a query or other running tasks:
If an activity is consuming too many resources, or is running too
long, you can cancel it. Canceling an activity is gentler than forcing
the application that submitted the activity. A canceled activity
returns SQL4725N to the user, but does not end the connection or
affect any other user activity. Forcing the application ends both the
connection and user activities.
In your procedure you are looking for the app handle, uow and a specific activity ID. Have you looked what the activity you are going to cancel is/was doing? You could use WLM_CAPTURE_ACTIVITY_IN_PROGRESS to first dump information about that activity, so that you can debug your scenario.

Related

DB2-12 (Z/OS) - Create Alias for Stored Procedure

it's possible to define an alias for a stored procedure (sql-native)?
In the documentation, reference is made only to: SEQUENCE and TABLES
1) CREATE PROCEDURE OWXXCOLL.STORED1()
2) CREATE ALIAS DB2C.STORED1 FOR OWXXCOLL.STORED1;
3) CALL DB2C.STORED1();
EDIT 2021-05-14
The original question arises for the following problem (I was hoping to get away with using aliases)
Intro
I have defined a native SP
The OWXXCOLL schema is the same one I also use for tables/index...
(I noticed that the tables also have different aliases)
CREATE PROCEDURE OWXXCOLL.STORED1(...)
LANGUAGE SQL
ISOLATION LEVEL CS
WLM ENVIRONMENT FOR DEBUG MODE WLMENV1
ALLOW DEBUG MODE
BEGIN
...
END#
I also modified the cobol program (name:PGMSTO1) to call the Stored with the CALL statement (without qualifier)
EXEC SQL
CALL STORED1 (...)
END-EXEC.
The problem
The various table accesses (SELECT) work correctly BUT When I run the PGMSTO1 the call to the Stored ends with sqlcode -440
NO AUTHORIZED PROCEDURE BY THE NAME STORED1 HAVING COMPATIBLE ARGUMENTS WAS FOUND<
The error comes from the fact that it is not using the owner OWXXCOLL but DB2C (DB2C is user who scheduled the jcl/batch)
If I enter the qualifier (OWXXCOLL) the call it's OK.
I don't understand what to check and what configurations are missing.
Thanks
The cobol program (PGMSTO1) that calls the stored procedure has the following BIND parameters:
COLLID NAME OWNER CREATOR QUALIFIER DYNAMICRULES PATHSCHEMAS
OWXXCOLL PGMSTO1 DB2C DB2C FPXX B "DB2C"
"DB2C" path is used to resolve unqualified stored procedure
I will need to modify the bind parameter "PATH".
I will try to ask to add my schema as well (OWXXCOLL)
PATH("OWXXCOLL","DB2C")

How to expend tAssertCatcher to catch more errors than its default in talend?

I have a job which when I run it- I get this:
[ERROR] 11:47:54 org.talend.components.snowflake.runtime.SnowflakeRowStandalone- Query execution has
failed. Please validate your query.
net.snowflake.client.jdbc.SnowflakeSQLException: Execution error in store procedure
SP_GENERAL:
Numeric value '' is not recognized
but when I'm trying to catch this error- I cant.
I tried tAssertCatcher, tLogCatcher, tStatCatcher- and nothing has worked.
could anybody help please?
ok, finally I got a solution.
tAssertCatcher does not catch errors from stored procedures, so I created a joblet which contain the tAssertCatcher AND in addition, added in there:
input with schema almost identical to tAssertCatcher's schema:
moment, pid, project, job, language, origin, status, substatus, errorCode, errorMessage.
now- I connected between the tDBrow component which I want to catch error from this process- with Reject row to the joblet, and pass errorCode and errorMessage- this will be the exception and description.
in the schema I used tMap to add variables values to almost all the columns:
pid, status, jobName, projectName and the rest I passed hardcoded.
finally I got a solution... every time I'll have error in stored procedure- I'll get 2 detailed records: one that I created manually, and the another one is UNEXPECTED-EXCEPTION.
the additional part in the joblet

Firedac: connection assigned to transactions

I'm using Delphi 10.4 with a Firebird-Database (3) and FireDac. I have a general question about transaction handling.
Please have a look at the following pseudo code:
write_transaction := TFDTransaction.Create;
write_connection := TFDConnection.Create;
write_transaction.Connection := write_connection;
write_connection.StartTransaction;
There is a connection assigned to a transaction. Then I start working with:
write_transaction.StartTransaction;
...
write_transaction.Commit;
But when I call write_connection.StartTransaction what will happen? So my questions...
Will there be started a transaction for the write_transaction, as if write_transaction.StartTransaction is called? Or will there be started a completely different transaction?
Will there be started a transaction for the write_transaction, as if
write_transaction.StartTransaction is called?
Yes, this is the same. The TFDTransaction component wraps the transaction control functionality into a component. Practically, it offers the same transaction functionality as TFDConnection, but allows you to group commands and datasets by linking them to a specific transaction object.

EOleException: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record

I get this exception:
EOleException: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record
trying to delete a record:
if SetupTable.Locate('MyFieldName', AKey, []) then
SetupTable.Delete
What happens here is that there is a check for if a record in the database exists, and if so it is deleted. My problem is that the record does exist, but deleting it produces the above exception.
It's a single user setup, and there is no way the record could disappear in between the execution of those two lines.
This code has been running fine for 8 years. The exception only occurs on Windows 8. I've seen it at 5 different customer sites. Customers using Windows XP, Vista, 7 dont see the problem.
I use Delphi XE to access an MS Access database through ADO with provider Microsoft.Jet.OLEDB.4.0
here is a stack dump:
0073f59d DSALon.exe ADODB 4712 DoRecordsetDelete
0073f5b6 DSALon.exe ADODB 4719 TCustomADODataSet.InternalDelete
006b3dd1 DSALon.exe DB 12947 TDataSet.CheckOperation
006b3ad8 DSALon.exe DB 12856 TDataSet.Delete
007cade6 DSALon.exe DatabaseUnit 629 ClearSetup
The offending bit of code in ADODB look like this:
procedure DoRecordsetDelete(DataSet: TCustomADODataSet; AffectRecords: TAffectRecords);
begin
with DataSet do
try
Recordset.Delete(AffectRecordsValues[AffectRecords]);
{ When CacheSize > 1, Recordset allows fetching of deleted records.
Calling MovePrevious seems to work around it }
if (CacheSize > 1) and (PRecInfo(ActiveBuffer).RecordNumber <> 1) then
begin
Recordset.MovePrevious;
Recordset.MoveNext;
end;
Recordset.MoveNext;
except
on E: Exception do
begin
Recordset.CancelUpdate;
DatabaseError(E.Message);
end;
end;
end;
which leads me to think that the CacheSize is relevant here. I do use a CacheSize > 1.
The MSDN help on ADO CacheSize property says:
If CacheSize is set to a value greater than one, the navigation methods (Move, MoveFirst, MoveLast, MoveNext, and MovePrevious) may result in navigation to a deleted record, if deletion occurs after the records were retrieved. After the initial fetch, subsequent deletions will not be reflected in your data cache until you attempt to access a data value from a deleted row. However, setting CacheSize to one eliminates this issue since deleted rows cannot be fetched.
Still, I'm 100% sure that the record that I'm trying to delete isn't already deleted.
But maybe doing a Resync before the Locate might avoid the problem..

db2 stored procedure error when update statement follows rollback

I have a stored procedure where at the end I check for errors and if there are errors I perform a rollback and then update the status on the batch table to 'FAILED'. When I run the stored procedure I regularly get an SQLCODE 818 error saying there is 'a timestamp conflict occurred'.
When I remove the update statement that changes the status on the batch table, I do not get the error.
What is the best practice to perform these actions so I avoid getting the error?
The section of code looks like this:
IF v_error_count > 0 THEN
-- Batch failed
ROLLBACK;
UPDATE batch_table bt
SET bt.batch_status = 'FAILED'
WHERE batch_id = input_batch_id;
END IF;
Thanks for any help.
SQL Code -818 indicates that the internal timestamp DB2 uses to ensure consistency between the running module matches the DBRM version created when the SQL Statements were precompiled.
You might check with your DBA (or someone else at your site), because the specific steps you have to perform may vary. For a general overview, you can see this article on IBM Knowledge Center.

Resources