Db2 SQLCODE

SQLCODE -922: Authorization failure

SQLCODE -922 (SQLSTATE 42505) means Db2 refused the connection, or the use of the plan, for this authorization ID. The message gives the kind of check that failed and a reason code, such as 00F30034.

Also written as SQL -922, SQLCODE=-922, SQLCODE = -922, db2 -922, sqlstate 42505, plan access error, 00F30034.

What it means

Before a program can run any SQL, Db2 checks two things. The first is whether the user may connect to the Db2 subsystem from this environment, such as batch, TSO or CICS. The second is whether the user's authorization ID may execute the plan. If either check fails, the connection, or the first SQL statement, gets -922.

The message has an error type, such as PLAN ACCESS, and a reason code. PLAN ACCESS with reason 00F30034 means the ID isn't authorized to run the plan, which is the case you'll see most. A PLAN ACCESS error can also mean the plan doesn't exist, so check the plan name too.

Connection checks are normally done by RACF, through profiles in the DSNR class. A batch or TSO connection to subsystem DB2P, for example, needs READ access to the profile DB2P.BATCH. A refused connection carries a different error type and reason code from a plan failure, and some attachments report it with their own message as well.

Common causes

  • The user ID that runs the job has no EXECUTE privilege on the plan, and neither do its RACF groups.
  • The job runs under a different user ID than expected, such as a scheduler ID that was never granted access.
  • In CICS, AUTHID or AUTHTYPE on the DB2ENTRY or DB2CONN passes Db2 a different ID from the one that was granted access.
  • RACF doesn't permit the user to connect to the subsystem from this environment through the DSNR class profiles.
  • The plan was freed and bound again, which drops all EXECUTE grants on it.

How to find the problem

  1. Read the error type and reason code in the DSNT408I message.
  2. Work out which ID Db2 checked. In batch it's normally the job's RACF user. In CICS it comes from AUTHID or AUTHTYPE on the DB2ENTRY or DB2CONN.
  3. Check grants on the plan with SELECT GRANTEE, EXECUTEAUTH FROM SYSIBM.SYSPLANAUTH WHERE NAME = 'PAYPLAN'. The grant may be to PUBLIC, to a group or to the user.
  4. For a connection failure, ask the security team to check the user's access to the DSNR profiles for the subsystem.

How to fix it

  • Grant EXECUTE on the plan, preferably to a RACF group the user belongs to, with GRANT EXECUTE ON PLAN PAYPLAN TO PAYGRP.
  • Run the job under the right user ID, or have the scheduler's ID granted access.
  • In CICS, correct AUTHID or AUTHTYPE on the DB2ENTRY so Db2 sees an ID that holds the grant.
  • For a connection failure, have RACF permit the user or group READ access to the right DSNR profile.
  • Change a plan with REBIND, or BIND PLAN with ACTION(REPLACE), rather than FREE and BIND. Existing EXECUTE grants stay in place. Add RETAIN if the bind also changes the plan's owner, or Db2 revokes EXECUTE from the old owner.

What it looks like

PAYRUN01 STEP010 - DSN RUN PROGRAM(PAYCALC) PLAN(PAYPLAN)
DSNT408I SQLCODE = -922, ERROR:  AUTHORIZATION FAILURE: PLAN ACCESS ERROR. REASON 00F30034
DSNT418I SQLSTATE   = 42505 SQLSTATE RETURN CODE

Questions

What's the difference between -922 and -551?

-922 stops you at the door, because you can't connect or can't run the plan. -551 means you got in and ran the plan, but lack a privilege on one table or other object.

Why does the job work for me but fail under the scheduler?

The scheduler runs it under its own user ID, and that ID or its groups haven't been given EXECUTE on the plan or access to the subsystem.

Does -922 need a REBIND?

No. It's an authorization problem. A GRANT or a RACF change fixes it without touching the program or the plan.