Was this helpful?
CONNECT
Valid in: ESQL, OpenAPI, ODBC, JDBC, .NET
The CONNECT statement connects the application to a database and, optionally, to a distributed transaction.
The CONNECT statement has the following format:
EXEC SQL CONNECT dbname
              [SESSION session_number]
              [IDENTIFIED BY username]
              [OPTIONS = flag {, flag}]
              [WITH options]
dbname
Specifies the database to which the session connects. Dbname can be a quoted or unquoted string literal or a host string variable. If the name includes any name extensions (such as a system or node name), string literals must be quoted.
SESSION session_number
Specifies a positive integer literal or variable whose value must be unique among existing session numbers in the application. A value of 0 is equivalent to omitting the SESSION clause.
IDENTIFIED BY username
Specifies the user identifier under which this session runs. Username can be specified using a quoted or unquoted string literal or string variable.
Note:  Some Enterprise Access products do not support the IDENTIFIED BY clause.
OPTIONS = flag
Specifies runtime options for the connection. Valid flags are those accepted by the SQL command. Flags specific to the Terminal Monitor are not valid. For more information about these flags, see the System Administrator Guide.
The flags can be specified using quoted or unquoted character string literals or string variables.
The maximum number of flags is twelve.
WITH options
Specifies Enterprise Access product specific connection parameters. The command line +c flag provides access to the CONNECT statement’s Enterprise Access product WITH clause. For a discussion of the Enterprise Access product with clause, see DBMS Extensions in the chapter “OpenSQL Feature.”
For a list of the valid WITH clause options for a specific Enterprise Access product, see your Enterprise Access product guide.
The embedded SQL CONNECT statement connects an application to a database, similar to the operating-system-level SQL and ISQL commands. The CONNECT statement must precede all statements that access the database. The CONNECT statement cannot be issued in a dynamic OpenSQL statement.
Use the SESSION clause if your application includes multiple open sessions (see Multiple Session Connections on page 151). The SESSION clause uniquely identifies each session, by associating each session with the specified session_identifier. The session identifier must be a positive integer.
Multiple-session applications require the SESSION clause on each CONNECT statement including the first. If this clause is not present on the first connect in the application, OpenSQL assumes that the application does not use multiple open sessions, and subsequent attempts to open other sessions generate an error.
To switch from one existing session to another existing session, use the SET_SQL statement. The CONNECT statement with the SESSION clause is used only to establish new sessions. You can, however, open more than one session with the same database.
The identified by clause allows the session to run as the specified user, like the -u flag of the SQL command. To determine whether your Enterprise Access product supports the -u flag (and, therefore, the identified by clause), see your Enterprise Access product guide.
The OPTIONS clause allows up to twelve flags to be specified that control session behavior. For details about these flags, see the description of the SQL command in the Command Reference Guide. Not all flags are supported by all Enterprise Access products.
The WITH clause (see Enterprise Access and EDBC With Clause on page 159) enables Enterprise Access product‑specific connection parameters to be specified. To determine the options supported by a specific Enterprise Access product, see your Enterprise Access product guide.
Last modified date: 12/14/2023