DISCONNECT

Embedded SQL for C and SQL Server

Embedded SQL for C and SQL Server

DISCONNECT

The DISCONNECT statement disconnects one or all database connections.

Syntax

DISCONNECT [connection_name | ALL | CURRENT]

Arguments

connection_name

Is the connection to be disconnected.

ALL

Specifies disconnecting all connections. This option must be used before you can exit the program.

CURRENT

Specifies disconnecting the current connection. The current connection is either the most recent connection established by a CONNECT TO statement or a subsequent connection set by a SET CONNECTION statement.

Remarks

When a connection is disconnected, all cursors opened for that connection are automatically closed.

To ensure a clean exit, an Embedded SQL program must issue a DISCONNECT ALL statement before it exits the main application.

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 takes 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

SET CONNECTION