SET CONNECTION

Embedded SQL for C and SQL Server

Embedded SQL for C and SQL Server

SET CONNECTION

The SET CONNECTION statement specifies which database connection to use for subsequent SQL statements.

Syntax

SET CONNECTION connection_name

Arguments

connection_name

Is the name of an existing database connection.

Remarks

The value for connection_name must match the connection name specified in a previous CONNECT TO statement. The connection_name can be either the connection's literal name or a host variable that contains character values. SET CONNECTION can be used only with a named connection.

If you are using connections across compilation modules, you must use named connections.

Examples
EXEC SQL CONNECT TO caffe.pubs AS caffe1 USER sa;
EXEC SQL CONNECT TO latte.pubs AS latte1 USER sa;
EXEC SQL SET CONNECTION caffe1;
EXEC SQL SELECT name FROM sysobjects INTO :name;
EXEC SQL SET CONNECTION latte1;
EXEC SQL SELECT name FROM sysobjects INTO :name;
EXEC SQL DISCONNECT caffe1;
EXEC SQL DISCONNECT latte1;
// The first select will take place against the pubs //
// database on server "caffe." The second SELECT will //
// take place against the pubs database on server "latte." //
// In place of the two "disconnect" statements at the end, //
// you can also write: //
// EXEC SQL DISCONNECT ALL; //

See Also

CONNECT TO