Programming Guide : Working with a Database : How Programming for Multiple Sessions Works : How You Can Keep Track of the Current Session
 
Share this page          
How You Can Keep Track of the Current Session
The DBSession attribute, defined for the ProcExec class and inherited by the GhostExec, FrameExec, and MethodExec classes, identifies the current database session for the application. This attribute contains the DBSessionObject object.
For more information about using this attribute, see How You Can Switch Database Sessions.
How You Can Access the DBSessionObject Object
Each open database session in an application has an associated DBSessionObject object. The attributes of this object identify the database associated with the session, the session's ID, and the DBMS flags with which the session was opened. There are also DBSession Object attributes that provide status information about the session:
Database
Contains the name of the database accessed by the session
DBMSError
Contains the database-specific error number associated with the most recently executed SQL statement in the session
ErrorNumber
Contains the generic error numbers of any error resulting from the most recently executed SQL statement in the session
RowCount
Contains the number of rows affected by the most recently executed SQL statement in the session
State
Contains the connection state of the session (DS_CONNECTED or DS_DISCONNECTED)
For more information about the DBSessionObject's attributes, see the Language Reference Guide.
You can access the DBSessionObject object through the following ways:
DBSession attribute of the FrameExec object—for running frames
ProcExec object—for 4GL procedures
MethodExec—for user class methods
For example, the following statement assigns the name of the current session's associated database to the variable dbname:
dbname = CurFrame.DBSession.Database;
OpenROAD automatically assigns the DBSessionObject object for the application's starting session to the DBSession attribute of the application's starting component. Subsequent frames or procedures inherit the DBSessionObject from their calling component, unless you explicitly change sessions for that component.
For instructions to change sessions, see Connect Method and How You Can Switch Database Sessions.