Db2 SQLCODE

SQLCODE -906: Function disabled by a prior error

SQLCODE -906 (SQLSTATE 51005) means Db2 refused the statement because an earlier error disabled SQL for this program. Every later SQL call fails with -906 too, so the program should normally end.

Other names for this code

Also written as SQL -906, SQLCODE=-906, SQLCODE = -906, db2 -906, sqlstate 51005, SQL0906N, function is disabled due to a prior error, DSNCEXT1 -906.

What it means

Some failures leave the connection between the program and Db2 in a state where Db2 won't accept more work. After that, each SQL statement gets -906 straight away. The statement that gets -906 isn't the problem. The error that came before it is.

IBM gives two common ways to reach it.

  • The program caught an abend and kept going. A PL/I ON ERROR unit, or any handler that intercepts an abend, can let the program run more SQL after Db2 has given up on it.
  • A Db2 CICS transaction hit an error while creating its thread and kept issuing SQL without a SYNCPOINT ROLLBACK first.

In the CICS case, the SQLERRP field of the SQLCA holds DSNCEXT1. That transaction can issue SYNCPOINT ROLLBACK and continue, but only if it can deal with whatever made the thread creation fail.

Db2 for LUW uses SQL0906N, with SQLSTATE 24514, 51005 or 58023 depending on the case.

Common causes

  • A program handled an abend in its own error routine and carried on issuing SQL.
  • A CICS transaction got an error while its Db2 thread was being created, then ignored it and ran more SQL.
  • A Language Environment condition handler resumed after a failure inside Db2 processing.
  • A loop in the program keeps retrying SQL after the first failure without checking the SQLCODE.

How to find the problem

  1. Look back in the job log, CICS log or transaction dump for the first error. It may be an abend code or an earlier SQLCODE such as -922 or -923.
  2. In CICS, check SQLERRP in the SQLCA. DSNCEXT1 there points to a thread creation error.
  3. Read the program's abend and condition handling. Find where it resumes after an error and what SQL it runs next.
  4. Check whether the first -906 came right after an abend message for the same task or job step.

How to fix it

  • End the program when it gets -906, and fix the first error.
  • Change abend handlers so they don't resume and run SQL after a failure inside Db2.
  • In CICS, issue EXEC CICS SYNCPOINT ROLLBACK when SQLERRP is DSNCEXT1, and continue only if the transaction can correct the cause.
  • Fix the thread creation problem itself, such as a plan authorization failure or an unavailable connection, then rerun.

What it looks like

DSNT408I SQLCODE = -906, ERROR:  THE SQL STATEMENT CANNOT BE EXECUTED BECAUSE THIS
         FUNCTION IS DISABLED DUE TO A PRIOR ERROR
DSNT418I SQLSTATE   = 51005 SQLSTATE RETURN CODE

IBM documentation

IBM documentation: -906. Use the documentation for your installed release.

Report a correction to WND Software.

Questions

Will retrying the statement help?

No. Every later statement in the program gets -906 until it ends, or in CICS until a SYNCPOINT ROLLBACK when the thread creation case applies.

Where is the real error?

Earlier in the log. Look for an abend or an SQLCODE before the first -906.

How is -906 different from -901?

After -901, later statements can still work. After -906, they all fail.