Page 1 of 1

AssignConnect doesn't share transaction

Posted: Thu 24 Oct 2013 12:11
Hi.

I use odac90d17pro for RADStudioXE3.
In my project I have two independent modules (dll libraries). In first I create session by TOraSession. Next I pass that session pointer to second module. In second module I create another TOraSession and use AssignConnect.
In my previous version of ODAC (odac690d10pro) and BDS2006 when I started transaction in first module, I saw that same transaction in second module. Now, operation made in both session are invisible each other.
My intention is to have one transaction in both modules. Database modyfication in one module should be visible in second module.
Why it doesn't work now?

Regards
Wojciech Sitterlee

Re: AssignConnect doesn't share transaction

Posted: Fri 25 Oct 2013 06:42
by AlexP
Hello,

We cannot reproduce the problem. Please send a small project (both application and library) reproducing the problem to alexp*devart*com

Re: AssignConnect doesn't share transaction

Posted: Fri 25 Oct 2013 09:06
It is a difficult because source code is a part of a big project.
Could you agree that both session should be visible as one transaction in this case?
How exactly works 'AssignConnect'? Copy parameters of session? Copy transaction pointer?
Is it right way to pass session pointer to other module?

Re: AssignConnect doesn't share transaction

Posted: Fri 25 Oct 2013 11:08
by AlexP
Hello,

There is a sample of a console application and a library demonstrating work with transaction in a DLL. Please enter correct server names, password, login and your PC name, execute the application and let us know the results.

Code: Select all

library DllPrj;

uses
  SysUtils,
  Classes,
  Ora;


var
  InternalSession: TOraSession;

procedure AssignSession(Session: TOraSession); cdecl;
begin
  InternalSession := TOraSession.Create(nil);
  InternalSession.AssignConnect(Session);
end;

function CheckTransaction: Boolean;
begin
  Result :=  InternalSession.InTransaction;
end;

procedure SessionFree; cdecl;
begin
  InternalSession.Free;
end;

exports
  AssignSession,
  CheckTransaction,
  SessionFree;

begin
end.

Code: Select all

program ConsolePrj;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Windows,
  Variants,
  Ora;

type
  TAssignSession = procedure (Session: TOraSession); cdecl;
  TCheckTransaction = function: boolean; cdecl;
  TSessionFree = procedure; cdecl;
var
  OraSession, OraSessionCheck: TOraSession;
  hDLL:HModule;
  AssignSession: TAssignSession;
  CheckTransaction: TCheckTransaction;
  SessionFree: TSessionFree;

begin
  OraSession := TOraSession.Create(nil, 'login/passwd@SID');
  try
    OraSession.Connect;
    OraSession.StartTransaction;

    hDLL := 0;
    hDLL := LoadLibrary('DllPrj.dll');
    try
      if hDLL <> 0 then begin
        @AssignSession := GetProcAddress(hDLL, 'AssignSession');
        if @AssignSession <> nil then
          AssignSession(OraSession)
        else
          Exit;

        @CheckTransaction := GetProcAddress(hDLL, 'CheckTransaction');
        if @CheckTransaction <> nil then begin
          OraSessionCheck := TOraSession.Create(nil, 'login/passwd@SID as SYSDBA');
          try
            OraSessionCheck.Connect;
            OraSessionCheck.ExecSQL('begin select count(*) into :p1 FROM v$transaction t, v$session s WHERE t.ses_addr = s.saddr AND MACHINE = ''PC_NAME''; end;',[0]);

            Writeln(Format('Dll InTransaction: %s; Transaction Count %d',[VarToStr(CheckTransaction), OraSessionCheck.SQL.ParamByName('p1').AsInteger]));
          finally
            OraSessionCheck.Free;
          end;
        end
        else
          Exit;

        @SessionFree := GetProcAddress(hDLL, 'SessionFree');
        if @SessionFree <> nil then
          SessionFree;
      end;
    finally
      FreeLibrary(hDLL);
    end;
  finally
    OraSession.Free;
  end;
  Readln;
end.

Re: AssignConnect doesn't share transaction

Posted: Mon 28 Oct 2013 09:52
Results:
"Dll InTransaction: True; Transaction Count 0"

Edit:

Sorry, I didn't change machine name in query.

Results:
"Dll InTransaction: True; Transaction Count 1"

Re: AssignConnect doesn't share transaction

Posted: Mon 28 Oct 2013 12:23
by AlexP
Hello,

Most probably, you have specified an incorrect PC name in the MACHINE = 'PC_NAME' query, therefore the number of transactions is 0.

Re: AssignConnect doesn't share transaction

Posted: Tue 29 Oct 2013 08:08
Yes, I wrote in previous post about that mistake. Result is 1.

Re: AssignConnect doesn't share transaction

Posted: Tue 29 Oct 2013 10:04
by AlexP
Hello,

This result means, that one and the same transaction is used when assigning session with the AssignConnect method.

Re: AssignConnect doesn't share transaction

Posted: Tue 29 Oct 2013 11:31
We have found the problem. There was anywhere else.
You had to change apparently, something with AutoCommit property in TOraQuery. Despite passing session pointer from first modul, opening query in second module caused openig new transaction. That's why we have two transactions.

Anyway thank you for your help :-)

Re: AssignConnect doesn't share transaction

Posted: Tue 29 Oct 2013 12:19
by AlexP
Hello,

Please modify the code I have sent you, so that the described behaviour is reproduced, and send it back, in order for me to be able to investigate the problem.

Re: AssignConnect doesn't share transaction

Posted: Mon 04 Nov 2013 09:38
Hello

I can't reproduce that situation in your example. It works :-)
In my C++ code I had to change one line of code:

q->AutoCommit = false

to:

q->AutoCommit = q->Session->AutoCommit;

where 'q->Session' is comming from outside library and also is 'false'.

Re: AssignConnect doesn't share transaction

Posted: Fri 08 Nov 2013 13:22
by AlexP
Hello,

This problem may be directly due to the IDE. Try to reproduce the problem on another IDE version or send us your ะก++ project - and we will check this behaviour on various IDEs.