IBM Books

SQL Reference

SET CONNECTION

The SET CONNECTION statement changes the state of a connection from dormant to current, making the specified location the current server. It is not under transaction control.

Invocation

Although an interactive SQL facility might provide an interface that gives the appearance of interactive execution, this statement can only be embedded within an application program. It is an executable statement that cannot be dynamically prepared.

Authorization

None Required.

Syntax

>>-SET CONNECTION---+-server-name---+--------------------------><
                    '-host-variable-'
 

Description

server-name  or  host-variable
Identifies the application server by the specified server-name or a host-variable which contains the server-name.

If a host-variable is specified, it must be a character string variable with a length attribute that is not greater than 8, and it must not include an indicator variable. The server-name that is contained within the host-variable must be left-justified and must not be delimited by quotation marks.

Note that the server-name is a database alias identifying the application server. It must be listed in the application requester's local directory.

The server-name or the host-variable must identify an existing connection of the application process. If they do not identify an existing connection, an error (SQLSTATE 08003) is raised.

If SET CONNECTION is to the current connection, the states of all connections of the application process are unchanged.

Successful Connection 

If the SET CONNECTION statement executes successfully:

Unsuccessful Connection 

If the SET CONNECTION statement fails:

Notes

Examples

Execute SQL statements at IBMSTHDB, execute SQL statements at IBMTOKDB, and then execute more SQL statements at IBMSTHDB.

   EXEC SQL CONNECT TO IBMSTHDB;
   /* Execute statements referencing objects at IBMSTHDB */

   EXEC SQL CONNECT TO IBMTOKDB;
   /* Execute statements referencing objects at IBMTOKDB */

   EXEC SQL SET CONNECTION IBMSTHDB;
   /* Execute statements referencing objects at IBMSTHDB */

Note that the first CONNECT statement creates the IBMSTHDB connection, the second CONNECT statement places it in the dormant state, and the SET CONNECTION statement returns it to the current state.


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]