The Virtual System Table
_MyConnection introduced in Version 9.0A has one record for the current connection to a database, and provides the following fields:
- _MyConn-NumSeqBuffers : Number of private read-only buffers currently allowed.
- _MyConn-Pid : This user's process ID.
- _MyConn-UsedSeqBuffers: Number of private read-only buffers currently in use.
- _MyConn-UserId: The user's user ID.
When connected to a single database the following code will return the
user number for the current 4GL/ABL session:
FIND _MyConnection.
DISPLAY _MyConn-UserId.
To find the PID of the Database Server to which the current remote user is connected you first need to find the _myconnection record (there is only ever 1), then find the _connect record whose _connect-usr matches _myconnection._myconn-userid, then find the _connect record whose _connect-usr matches your _connect-server value.
/* When connected to multiple databases, this table should be queried with the DatabaseName:
FIND <MyDatabase>._connect */
DEFINE VARIABLE iServerNum AS INTEGER NO-UNDO.
FIND _Myconnection.
FIND _connect WHERE _connect._connect-usr = _Myconnection._myconn-userid.
iServerNum = _connect._connect-server.
FIND FIRST _connect WHERE _connect._connect-usr = iServerNum.
DISPLAY _connect._connect-pid.
To show all database connections of the current client, listing the: logical DB name, physical DB name, and user number:
DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DO iCount = 1 TO NUM-DBS:
CREATE BUFFER hBuffer FOR TABLE LDBNAME(iCount) + "._myConnection".
hBuffer:FIND-FIRST().
DISPLAY LDBNAME(iCount) PDBNAME(iCount) hBuffer::_myConn-UserID.
DELETE OBJECT hBuffer.
END.