CONNECT TO

Opens a new database session in multi-session mode.

Syntax

CONNECT TO { dbname | DEFAULT } [ AS session ]
    [ USER username USING password ]
    [ WITH CONCURRENT TRANSACTION ]
  1. dbname is a string expression identifying the database specification.
  2. session is a string expression identifying the database session. By default, it is dbname.
  3. username is a string expression identifying the name of the database user.
  4. password is a string expression identifying the password of the database user.

Usage

The CONNECT TO instruction opens a database connection. If the instruction successfully connects to the database environment, the connection becomes the current database session for the program.

The session name is case-sensitive.

A program can connect to several database environments at the same time, and it can establish multiple connections to the same database environment, provided each connection has a unique connection name.

The connection is closed with the DISCONNECT instruction, or when the program ends.

With IBM® Informix® database servers, when using the DEFAULT keyword, you connect to the default IBM Informix database server, identified by the INFORMIXSERVER environment variable, without any database selection.

When the USER username USING password clause is specified, the database user is identified by username and password, ignoring all other user settings defined in FGLPROFILE or as connection string parameters.

The WITH CONCURRENT TRANSACTION clause allows a program to open several transactions concurrently in different database sessions. This is supported for IBM Informix database servers and must be avoided with other database server types.

A CONNECT TO statement cannot be executed with dynamic SQL (i.e. PREPARE + EXECUTE).

When using IBM Informix databases on UNIX™, the only restriction on establishing multiple connections to the same database environment is that an program can establish only one connection to each local server that uses the shared-memory connection mechanism. To find out whether a local server uses the shared-memory connection mechanism or the local-loopback connection mechanism, examine the $INFORMIXDIR/etc/sqlhosts file.

MAIN
  DEFINE uname, upswd VARCHAR(50) 
  CONNECT TO "stores1" -- Session name is "stores1"
  CONNECT TO "stores1" AS "SA" -- Session name is "SA"
  CALL login_dialog() RETURNING uname, upswd
  CONNECT TO "stores2" AS "SB" USER uname USING upswd
END MAIN