AssignSvcCtx, how to use it properly?

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
DmitryV
Posts: 12
Joined: Mon 05 May 2014 04:33

AssignSvcCtx, how to use it properly?

Post by DmitryV » Mon 05 May 2014 05:04

ODAC 9.3
Possibility to assign external SvcCtx to connection is added
Hi, I want passing connection to dll, and try for testing...

Code: Select all

 
  OraSession1.Connect;  // this is main session     
  
  OraQuery1.Sql.Text := 'select sysdate as d from dual';
  OraQuery1.Session := OraSession2;
  OraSession2.AssignSvcCtx(OraSession1.OCISvcCtx);

  if OraSession2.Connected then
    // OraSession2 is connected now, it's right
    OraQuery1.Open;

    // this method returns OCI_INVALID_HANDLE 
ODAC 9.3.8, ORACLE 11.2.0.1.0
Delphi XE5, Win7

llleo
Posts: 10
Joined: Fri 18 Apr 2014 09:58

Re: AssignSvcCtx, how to use it properly?

Post by llleo » Mon 05 May 2014 07:47

Now TOraSession.OCISvcCtx is not pointer to SvcCtx in oracle clients.
Try to use

Code: Select all

OraSession2.AssignSvcCtx(OraSession1.OCISvcCtx.hOCISvcCtx);

DmitryV
Posts: 12
Joined: Mon 05 May 2014 04:33

Re: AssignSvcCtx, how to use it properly?

Post by DmitryV » Mon 05 May 2014 08:54

Yes, indeed... :) Thank you very much!

llleo
Posts: 10
Joined: Fri 18 Apr 2014 09:58

Re: AssignSvcCtx, how to use it properly?

Post by llleo » Mon 05 May 2014 11:42

This way working, but SetLDA is making AV:

Code: Select all

  OraSession1.Password:=***;
  OraSession1.Server:=***;
  OraSession1.Options.UseOCI7:=True;
  OraSession1.Connect;
  OraSession2.OCISvcCtx.SetLDA(OraSession1.LDA);
making AV because of OCISvcCtx is nil.

How i can assign external LDA(or translate it into SvcCtx)?

llleo
Posts: 10
Joined: Fri 18 Apr 2014 09:58

Re: AssignSvcCtx, how to use it properly?

Post by llleo » Tue 06 May 2014 09:38

Still waiting for comments from support......

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

Re: AssignSvcCtx, how to use it properly?

Post by AlexP » Wed 07 May 2014 10:08

The SetLDA method is obsolete, it was left for support for protocol version 7. If you are using Oracle 11, you should work with hOCISvcCtx.

llleo
Posts: 10
Joined: Fri 18 Apr 2014 09:58

Re: AssignSvcCtx, how to use it properly?

Post by llleo » Thu 08 May 2014 05:42

Strange answer....
In common situation i use OciSvc with oracle 9+, but in some situation i need protocol version 7 support.

I searching way to pass LDA pointer from other DAC(with ONLY OCI7 protocol) to ODAC session(it`s not important for me - in OCI7 or OCI8 mode).

How i can use this(or any other working) method to pass external LDA(or convert to SvcCtx)?

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

Re: AssignSvcCtx, how to use it properly?

Post by AlexP » Tue 13 May 2014 12:18

Please provide your working sample of LDA setup on the old ODAC versions (also, specify the previous ODAC version).

llleo
Posts: 10
Joined: Fri 18 Apr 2014 09:58

Re: AssignSvcCtx, how to use it properly?

Post by llleo » Tue 13 May 2014 13:37

I have a unit with helper class (under the influence of you TBDESession):

Code: Select all

unit uSharedOraSession;

interface

uses
  ORA, OraCall, DBAccess, classes, OraClasses, CRAccess;

type
  TSharedOraSession = class(TOraSession)
    protected
      FpLDA : Pointer;
      FpSVC : Pointer;
      procedure DoConnect; override;
      procedure DoDisconnect; override;
      procedure SetIConnection(Value: TCRConnection); override;
    public
      constructor Create(Owner: TComponent; aLDA, aSVC : Pointer); reintroduce;
      procedure CopyConnect(aSession: TOraSession);
  end;

implementation

procedure TSharedOraSession.SetIConnection(Value: TCRConnection);
begin
  inherited;
  FIConnection := Value as TOCIConnection;
end;

procedure TSharedOraSession.DoConnect;
begin
  if not OCIInited then
    InitOCI;
  CreateIConnection;
  Pooling:=False;
  if Options.UseOCI7 then
  begin
    FIConnection.SetOCICallStyle(OCI73);
    FIConnection.SetLDA(FpLDA);
  end
  else
  begin
    FIConnection.SetOCICallStyle(OraCall.OCICallStyle);
    FIConnection.SetSvcCtx(FpSVC)
  end;
  inherited;
end;

procedure TSharedOraSession.DoDisconnect;
begin
  try
    if Options.UseOCI7 then
      FIConnection.SetLDA(nil)
    else
      FIConnection.SetSvcCtx(nil);
  except
    on E: EDAError do
    begin
      if not((csDestroying in ComponentState) and E.IsFatalError) then
        Raise;
    end
    else
      Raise;
  end;
end;

constructor TSharedOraSession.Create(Owner: TComponent; aLDA, aSVC : Pointer);
begin
  inherited Create(Owner);
  FpLDA := aLDA;
  FpSVC := aSVC;
  ConnectPrompt := False;
  Options.EnableIntegers := False;
  Options.NeverConnect := True;
  Options.UseOCI7 := not Assigned(aSVC);
end;

procedure TSharedOraSession.CopyConnect(aSession: TOraSession);
begin
  if Assigned(aSession) then
  begin
    aSession.Options.UseOCI7 := Options.UseOCI7;
    aSession.AssignConnect(Self);
  end;
end;

end.
I have a form

Code: Select all

  object DBGrid1: TDBGrid
    DataSource = DataSource1
  end
  object Button1: TButton
    OnClick = Button1Click
  end
  object OraSession1: TOraSession
    Options.UseOCI7 = True
  end
  object OraSession2: TOraSession
    Options.UseOCI7 = True
  end
  object OraQuery1: TOraQuery
    Session = OraSession2
    SQL.Strings = (
      'select * from all_objects')
  end
  object DataSource1: TDataSource
    DataSet = OraQuery1
  end
And this working simple code for testing:

Code: Select all

  with TSharedOraSession.Create(nil,OraSession1.LDA,nil) do
    try
      Connect;
      CopyConnect(OraSession2);
      Disconnect;
    finally
      Free;
    end;
  OraQuery1.Session:=OraSession2;
  OraQuery1.Open;
This work very well in production with ODAC 4.05, 4.50, 6.50 (maybe 6.90) with a little changes(like

Code: Select all

E.IsFatalError
vs

Code: Select all

IsFatalError(E)
etc). While you not changed initialization procedure.

Hope this sample is enough?

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

Re: AssignSvcCtx, how to use it properly?

Post by AlexP » Wed 14 May 2014 08:22

Thank you for the sample. We will try to return the old behavior to the next build.

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

Re: AssignSvcCtx, how to use it properly?

Post by AlexP » Tue 27 May 2014 08:41

We have added the new method for using LDA - AssignLDA. This feature will be included in the next ODAC build.

llleo
Posts: 10
Joined: Fri 18 Apr 2014 09:58

Re: AssignSvcCtx, how to use it properly?

Post by llleo » Fri 30 May 2014 11:59

Can you give working sample - how to use AssignLDA ?

something like

Code: Select all

OraSession1.Create;
OraSession1.Connect;
...
OraSession2.AssignLDA(OraSession1.LDA);

I try some different combination and all of then is non-worknig....

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

Re: AssignSvcCtx, how to use it properly?

Post by AlexP » Fri 30 May 2014 13:42

The provided code is correct. Please describe in more details the difficulties appearing when using the AssignLDA method.

llleo
Posts: 10
Joined: Fri 18 Apr 2014 09:58

Re: AssignSvcCtx, how to use it properly?

Post by llleo » Tue 03 Jun 2014 10:50

I think my problem in UseOCI7 (http://forums.devart.com/viewtopic.php?f=5&t=29705)
I terminate my experiments until solution on this problem.

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

Re: AssignSvcCtx, how to use it properly?

Post by AlexP » Wed 04 Jun 2014 06:27

We haven't yet found a solution for the problem, we are still investigating the issue.

Post Reply