Was this helpful?
Creating Multiple Sessions
If your application requires more than one connection to a database, a session identifier or number can be assigned to each session, and the SET CONNECTION or SET_SQL (SESSION) statements can be used to switch sessions.
Using Session Identifiers
To assign a numeric session identifier to a connection, specify the session clause. For example:
EXEC SQL CONNECT accounting SESSION 99;
assigns the numeric session identifier 99 to the connection to the accounting database. To determine the session identifier for the current session, use the INQUIRE_SQL(SESSION) statement.
To switch sessions using the numeric session identifier, use the SET_SQL(SESSION) statement. For example:
EXEC SQL SET_SQL(SESSION = 99);
Using Connection Names
To assign a name to a connection, specify the AS clause. For example:
EXEC SQL CONNECT act107b AS 'accounting';
assigns the name, accounting, to the connection to the act107b database. To switch sessions using the connection name, use the SET CONNECTION statement. For example:
EXEC SQL SET CONNECTION 'accounting';
If the AS clause is omitted, the DBMS Server assigns a default connection name—the database specified in the CONNECT statement. This connection name can be used in subsequent SET CONNECTION statements to switch sessions. If the AS clause is omitted and a numeric session identifier is specified (using the SESSION clause), the default connection name is “iin,” where n is the specified numeric session identifier.
To determine the connection name for the current session, use the INQUIRE_SQL(CONNECTION_NAME) statement.
Last modified date: 08/29/2024