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 Informix ESQL/C, HCL Informix JDBC Driver, and HCL Informix 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';
  • Data Server Driver for JDBC and SQLJ
    • For a switch request without authentication requirements on a local-transaction, trusted connection, use the getDB2TrustedPooledConnection object.
      getDB2TrustedPooledConnection( String user_ID,
            java.util.Properties properties );
    • For a switch request without authentication requirements on a distributed-transaction, trusted connection, use the getDB2TrustedXAConnection object.
      getDB2TrustedXAConnection(String user_ID,
            java.util.Properties properties );
    • For a switch request with authentication requirements on a local-transaction, trusted connection, use the getDB2TrustedPooledConnection object, and include the new user's password.
      getDB2TrustedPooledConnection( String user_ID,
            String user_password, java.util.Properties properties );
    • For a switch request with authentication requirements on a distributed-transaction, trusted connection, use the getDB2TrustedXAConnection object, and include the new user's password.
      getDB2TrustedXAConnection( String user_ID, String user_password,
            java.util.Properties properties );
  • Data Server Provider for .NET
    • For a switch request without authentication requirements, use the TrustedContextSystemUserID property in the connection string.
      String connectString = "
         Server = IP_address/Local_host:port_number;
         Database = database_name;
         TrustedContextSystemUserID = user_ID
      ";
      
    • For a switch request with authentication requirements, use the TrustedContextSystemUserID and TrustedContextSystemPassword properties in the connection string.
      String connectString = "
         Server = IP_address/Local_host:port_number;
         Database = database_name;
         TrustedContextSystemUserID = user_ID;
         TrustedContextSystemPassword = user_password;
      ";