Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

DISCONNECT

SQL Server 2000

  New Information - SQL Server 2000 SP3.

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 $integrated;
EXEC SQL CONNECT TO latte.pubs AS latte1 USER $integrated;
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; //

Security Note  The preceding example uses the $integrated keyword to enable Windows Authentication. When possible, use this authentication method. If Windows Authentication is not available, prompt users to enter their credentials at run time. Avoid storing credentials in a file. If you must persist credentials, you should encrypt them with the Win32 cryptoAPI.

See Also

CONNECT TO

SET CONNECTION

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.