Switching the user ID on a trusted connection

You can switch user IDs after a trusted connection is established.

Before you begin

Ensure that at least one of the following statements is true:
  • The new user ID is the primary user ID defined in the trusted-context object.
  • The new user ID is explicitly defined as a user in the trusted-context object.
  • The trusted-context object is defined as WITH USE FOR PUBLIC.
Attention: During a user-ID switch, the database connection is maintained, but the switch results in a new connection environment. Objects such as temporary tables and WITH HOLD cursors are lost in the new environment.

Procedure

To switch to a different user, use the appropriate command in your application:
  • HCL OneDB™ ESQL/C, HCL OneDB JDBC Driver, and HCL OneDB ODBC Driver
    • For a switch request without authentication requirements, use the SET SESSION AUTHORIZATION statement without a user password.
      SET SESSION AUTHORIZATION TO 'user_ID';
    • For a switch request with authentication requirements, include the new user's password in the SET SESSION AUTHORIZATION statement.
      SET SESSION AUTHORIZATION TO 'user_ID' USING 'user_password';