AssignConnect doesn't share transaction

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
[email protected]
Posts: 27
Joined: Fri 12 Feb 2010 07:44

AssignConnect doesn't share transaction

Post by [email protected] » 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

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: AssignConnect doesn't share transaction

Post by AlexP » Fri 25 Oct 2013 06:42

Hello,

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

[email protected]
Posts: 27
Joined: Fri 12 Feb 2010 07:44

Re: AssignConnect doesn't share transaction

Post by [email protected] » 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?

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: AssignConnect doesn't share transaction

Post by AlexP » Fri 25 Oct 2013 11:08

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.

[email protected]
Posts: 27
Joined: Fri 12 Feb 2010 07:44

Re: AssignConnect doesn't share transaction

Post by [email protected] » 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"

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: AssignConnect doesn't share transaction

Post by AlexP » Mon 28 Oct 2013 12:23

Hello,

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

[email protected]
Posts: 27
Joined: Fri 12 Feb 2010 07:44

Re: AssignConnect doesn't share transaction

Post by [email protected] » Tue 29 Oct 2013 08:08

Yes, I wrote in previous post about that mistake. Result is 1.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: AssignConnect doesn't share transaction

Post by AlexP » Tue 29 Oct 2013 10:04

Hello,

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

[email protected]
Posts: 27
Joined: Fri 12 Feb 2010 07:44

Re: AssignConnect doesn't share transaction

Post by [email protected] » 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 :-)

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: AssignConnect doesn't share transaction

Post by AlexP » Tue 29 Oct 2013 12:19

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.

[email protected]
Posts: 27
Joined: Fri 12 Feb 2010 07:44

Re: AssignConnect doesn't share transaction

Post by [email protected] » 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'.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: AssignConnect doesn't share transaction

Post by AlexP » Fri 08 Nov 2013 13:22

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.

Post Reply