21
Views
4
Comments
Handle Database session
Application Type
Traditional Web, Mobile, Reactive, Service

How can I run a database command whenever a database session is used, and then run another command whenever the session is released?

I understand that there is a pool of database sessions shared among users. For each request, a database session is assigned, and then released at the end of this request.

I'm using an Oracle database and I want to pass the user ID to the database session context:

  • When a session is acquired: set session context with user ID as input. (dbms_sessions.set_context)
  • When a session is released: Clear the context (dbms_sessions.clear_context)

I was able to do this for each server action but there is a large number of server actions. So I'm looking for a centralized solution where this is done in the background without developer intervention.

Rank: #70

Hi Kahlil,


Have you taken a look at System Events?


In here you can centralize actions to run when a session starts (action to be executed in the first request to the server, after logging in, or on the first request after having logged out) or when a web request begins (action to be executed on each request to the server.), so you don't have to repeat it every time.


Note: this only applies for Traditional Web where session is maintained server side.


Hope it helps.


Regards,
João


Rank: #3742

OnBeginWebRequest would have been helpful if not for the following:

  • There is no alternative for mobile and reactive applications
  • There is no (OnEndWebRequest) to undo what I did in (OnBeginWebRequest) which is crucial.
Rank: #3742

Another limitation for OnBeginWebRequest:

  • Service actions are run in a separate transaction (different database session). So any changes done to the DB session in OnBeginWebRequest will not affect the service action's DB session.
  • The same goes for REST calls and timers