Top > Lycia reference > Querix 4GL > Statements > DISCONNECT
To meet your needs, we constantly work to improve Querix products.
This means that Lycia documentation is developing as well.
In case you have found a certain dissonance between the provided information and the actual behavior of Lycia 3 and/or your applications, please, let us know about this via documentation@querix.com so that we can introduce the necessary changes to our documentation.
Thank you for your attention and cooperation.
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:
Element |
Description |
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.
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.
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.
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 name of the session specified in the AS clause of the CONNECT TO statement.
The database name specified in the CONNECT TO statement, if the AS clause if omitted.
The DEFAULT keyword used instead of the session name disconnects the default database session established by the DATABASE statement.
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