DISCONNECT

DISCONNECT statement is used to close a database connection session opened previously by the CONNECT TO statement. It closes the given database connection, here is its syntax:

Session

A string expression identifying  the session name of the database connection to be terminated

 

This statement can close the database connections created both by means of the CONNECT TO statement and DATABASE statement. If a DISCONNECT statement is executed while a transaction is active, the transaction is automatically rolled back. Once a connection was disconnected, you cannot used the SET CONNECTION statement to specify it as the current connection. To use the disconnected session again you need to reopen it using the CONNECT TO statement.

No other session becomes active automatically once the current session gets disconnected. To be able to work with the SQL statements further, you need to set a new current connection either by executing a new CONNECT TO statement or by setting the current connection using the SET CONNECTION statement.

 

DISCONNECT ALL

The ALL keyword following the DISCONNECT statement terminates all connections to all databases previously opened, even the default connection opened by the DATABASE statement. If you execute this statement, you will not be able to execute SQL statements, even though you may have the DATABASE statement at the beginning of the main module defining the default database. To be able to execute SQL statements again, the program must execute either DATABASE or CONNECT TO statement after the DISCONNECT ALL statement was processed.

DISCONNECT CURRENT

The CURRENT keyword following the DISCONNECT statement terminates the current database connection. The current connection is the session of the last executed CONNECT TO statement or the session that was made the current one by the SET CONNECTION statement . If there were no CONNECT TO statements prior to it, the session established by the DATABASE statement is considered to be current.

Disconnecting a named session

You can disconnect any session that was preciously opened regardless of it being the current session or not. The DISCONNECT statement must be followed by the name of the session to be disconnected. The name of the session is case sensitive, it can be one of the following:

 

The example below leaves only one database session running, which is the session named db1:

DATABASE db

 

MAIN

...

CONNECT TO "db1"

CONNECT TO "db2"

CONNETC TO "db3" AS "session3"

...

DISCONNECT "session3"

DISCONNECT "db2"

DISCONNECT DEFAULT

SET CONNECTION "db1"

 

END MAIN

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.