SET CONNECTION

SET CONNECTION statement changes the current database session. Here is it syntax:

Session

A string expression identifying  the session name of the database connection that is to become the current session

A connection session becomes current automatically right after the corresponding CONNECT TO statement is executed. If another CONNECT TO is executed later, the session ceases to be the current one. Even if the next current connection is disconnected, the previously opened sessions do not become the current ones unless you explicitly instruct so by using the SET CONNECTION method.

 

The SET CONNECTION statement cannot be used for the sessions that were disconnected using the DISCONNECT statement.

SET CONNECTION DEFAULT

DEFAULT keyword used with the statement sets the connection specified by the DATABASE statement as the current connection. It is also used to set the default connection declared as CONNECT TO DEFAULT as the current connection.

DATABASE my_db

MAIN

...

CONNECT TO "ifx_db" -- this is the current connection at this point

...

SET CONNECTION DEFAULT -- the connection to my_db is current

SET CONNECTION session

You can set the current connection to a names database connection session declared previously by the CONNECT TO statement.

CONNECT TO "database1" -- current session database1

CONNECT TO "database2" -- current session database2

CONNECT TO "database3" -- current session database3

DISCONNECT CURRENT -- no current session. database3 session was deleted

 ...

SET CONNECTION "database2" -- current session database2

DORMANT and CURRENT DORMANT keywords

These keywords are applicable only for connecting to IBM Informix databases.

 

Adding the DORMANT keyword at the end of the statement makes the specified connection dormant instead of active. It allows you to set a database session inactive instead of disconnecting it. The main difference between setting a session dormant and using the DISCONNECT statement is that a dormant connection can be made active again using the SET CONNECTION statement. This would not be possible, if the session were disconnected.

 

You can set the current connection as dormant using the CURRENT DORMANT keywords or by specifying its name. However, once the current connection was set dormant, there will be no active connection until another SET CONNECTION or CONNECT TO statement is executed.

CONNECT TO "database1" -- current session database1

CONNECT TO "database2" -- current session database2

CONNECT TO "database3" -- current session database3

 

SET CONNECTION "database3" DORMANT -- no current session

#beginning from here no SQL statements can be executed

 ...

SET CONNECTION "database3" -- current session database3

# starting from here SQL statements can be used again

 

Contact Us

Privacy Policy

Copyright © 2024 Querix, (UK) Ltd.