Feedback
Did this article resolve your question/issue?

   

Article

How to retrieve user number and PID of DB connection

Information

 
TitleHow to retrieve user number and PID of DB connection
URL NameP19414
Article Number000135632
EnvironmentProduct: Progress
Version: 9.x
Product: OpenEdge
Version: All Supported Versions
OS: All Supported Platforms
Question/Problem Description
How to retrieve the user number for a connected database for the current session ?
How to find the PID of the Database server to which the current remote user is connected ?
How to retrieve the user PID of current session when connected to a database?
What is the purpose of the _Mycon-UserID field?
When was the MyConnection VST first introduced?
How to retrieve user number and PID of DB connection programmatically
Steps to Reproduce
Clarifying Information
Error Message
Defect Number
Enhancement Number
Cause
Resolution
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.

 
Workaround
Notes
References to Other Documentation:

Progress Documentation:
User connection (_MyConnection) (progress.com)

Progress Article(s):
How to disconnect all self and remote users from a database?
 
Last Modified Date1/12/2021 6:14 PM
Attachment 
Files
Disclaimer The origins of the information on this site may be internal or external to Progress Software Corporation (“Progress”). Progress Software Corporation makes all reasonable efforts to verify this information. However, the information provided is for your information only. Progress Software Corporation makes no explicit or implied claims to the validity of this information.

Any sample code provided on this site is not supported under any Progress support program or service. The sample code is provided on an "AS IS" basis. Progress makes no warranties, express or implied, and disclaims all implied warranties including, without limitation, the implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample code is borne by the user. In no event shall Progress, its employees, or anyone else involved in the creation, production, or delivery of the code be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample code, even if Progress has been advised of the possibility of such damages.