Difference between Share and passing a TOracleSession

ldsandon

Member³
I've downloaded the DLLDemo, and I've a question about the difference between passing a TOracleSession and using Share. The example says:

Code:
// This leads to one shared Session.
procedure LogonWithSession(Session: TOracleSession);

// The Share function 'copies' the connection to the DLLSession.
procedure LogonWithShare(Session: TOracleSession);
As far as I understand, the first method uses the same connection and session, while the second shares a connection but starts a new session ('copies')? The documentation is not clear about that, and I do not know OCI well enough to understand this.

That's because in some tests I made it looks I have two different transaction contexts (data modified by the sharing session are not seen in the shared one), and could get a deadlock while trying to modify the same data.

Therefore is it safe to "Share()" a session to a child thread, or a thread needs its own whole connection + session?
 
These functions are only relevant when using a DLL. When using thread you can simply pass the TOracleSession instance around.

The Share function is merely a convenient way to pass the handle to another session instance. It uses the same Oracle session, and therefore the same transaction context.
 
Again, I have to ask if Share() shares the connection or the session, because I have encountered the following issue: I have a Datasnap server that uses child datamodules. A main session is on the main remote datamodule, and it is passed to child datamodule when those are created.
When I connect the main session, I issue an ALTER SESSION SET CURRENT_SCHEMA statement. When in a child datamodule I call MainSession.Share(ChildSession), and try to execute a query, I get a "ora-00942 table does not exist" error - it looks I am not in the "main" session, but in a new one that was never altered. If I just set the datasets session to the main session everything works. I was using Share() because it is a handy way to change every dataset session at once with a single line of code, but in this case if they are not in the same session (and transaction), it's not what I need.
 
Again, I have to ask if Share() shares the connection or the session
The actual connection is shared. If you look at the v$session view, you will see just one session for your application.
 
Back
Top