CONNECT

The CONNECT statement (embedded SQL only) connects the application process to the specified XDB Server or DB2 (through XDB Link) location. This location becomes the current location for the application process.
Restriction: This topic applies to Windows environments only.

Invocation

CONNECT is an executable statement that can only be embedded in an application program. It cannot be dynamically prepared.

Authorization

The primary AuthID for the application process must be authorized to connect to the specified location. The specific AuthID required is determined by that location, with the authorization check also performed by that location.

Syntax

CONNECT 
    [TO {location-name | host-variable}] 
    [RESET]

Parameters:

location-name Identifies a specific XDB Server system location.
host-variable Names a host variable name containing a location name.

Description

The CONNECT statement is the embedded SQL equivalent of the interactive SET LOCATION TO command. The CONNECT statement connects an application process to a designated location or a host-variable containing a location name. When the CONNECT statement is executed, the location name must be known to the local XDB Server running the application, or the location name must appear in the LOCATION column of the SYSIBM.SYSLOCATIONS catalog within the SYSTEM location.

Host variables must conform to the following requirements:

  • Must be a character string variable with a length attribute of at least 16 characters.
  • Must be preceded by a colon and not be followed by an indicator variable.
  • Within the host variable, the location name must be left-justified and conform to the rules for forming an ordinary location identifier.
  • If the location name length is less than the length of the host variable, the remainder of the host variable must be padded on the right with blanks.

If the CONNECT statement execution is successful:

  • The application process is connected to the identified location.
  • The CURRENT SERVER special register is updated to contain the specified location name.
  • The SQLERRP field of the SQLCA is set to contain information about the location. This information has the format pppvvrrN, where:
    ppp identifies the product (for example, XDB or DB2)
    vv contains a two-digit version identifier (for example, '04')
    rr contains a two-digit release identifier (for example, '00')
    N indicates the Windows operating system

Examples:

The following code excerpt connects the application process to the system location:

EXEC SQL
    CONNECT TO system;

To connect the application to a location named in the host variable nameloc, execute the following command:

EXEC SQL
    CONNECT TO :nameloc;

The XDB Server implements the CONNECT command identically to DB2, except that the XDB Server improves performance by leaving the old location open after connecting with the new location.

CONNECT RESET

The CONNECT RESET statement is equivalent to a CONNECT TO specifying the local XDB Server location.

Note: Issuing this command is the only way to get back to an XDB Server location after connecting to a DB2 subsystem through the XDB Link.

CONNECT

The keyword CONNECT by itself returns information about the currently set XDB Server location. This information is placed in the SQLERRP field of the application SQLCA.

Note: The initial server of an application process is the currently set XDB Server location. An explicit or implicit execution of a CONNECT [TO] statement can establish a different location. A CONNECT [TO] statement directed to the currently set location is treated like any other CONNECT [TO]. The CURRENT SQLID special register is not reinitialized when CONNECT [TO] is used to connect back to the currently set location.