pOciSvcCtx

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
si2005
Posts: 3
Joined: Tue 16 Aug 2011 07:25

pOciSvcCtx

Post by si2005 » Tue 16 Aug 2011 09:06

Calling dll from exe with sending TOraSession.Con.OciSvcCtx is not worked (oci_invalid_handle). Error occured in SetSvcCtx procedure. What can i do ?

host application :

Code: Select all

 
  procedure p( Handle:pointer ); cdecl;
complied some years ago with ODAC 4.10

dll :

Code: Select all

 
  procedure p( Handle:pointer ); cdecl;
  begin
     OraSess := TOraSess.Create(application);
     // .... Setting direct, net, user, server, loginprompt, ...
     OraSess.ChangeConnect( handle );
  end;

complied with ODAC 6.9

Code: Select all

  TOraSess = class(TOraSession)
  public
     constructor Create(Owner: TComponent);
     destructor Destroy;

     procedure ChangeConnect(Handle : Pointer);
  end;

implementation
uses ...;

procedure TOraSess.ChangeConnect(Handle : Pointer);
begin
  Disconnect;
    if (FIConnection = nil) then CreateIConnection;

    // if not OCIInited then
    InitNet;
    FIConnection.Disconnect;
    // FIConnection.SetOCICallStyle(OCI80);
    FIConnection.SetSvcCtx( Handle ); // Here Error oci_invalid_handle
end;

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

Post by AlexP » Tue 16 Aug 2011 13:46

Hello,

To solve this problem, you can use the TOraSession.AssignConnect method for assigning connection by passing TOraSession to Dll (you can see the demo project demonstrating working with dll as an example: ..\devart\odac for xx\Demos\Miscellaneous\Dll\)

si2005
Posts: 3
Joined: Tue 16 Aug 2011 07:25

Post by si2005 » Wed 17 Aug 2011 05:19

Hello !

Yes, of course, AssignConnect worked, when library versions are equivalent, but we have ODAC version 4.10 in host application and dll have 6.9 ODAC version. And we cannot change library of host application. We'll try resolve this problem with another methods.

Thanks.

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

Post by AlexP » Wed 17 Aug 2011 09:22

Hello,

Try to add the following method to your Dll and call it before calling ChangeConnect

Code: Select all

TOraSess = class(TOraSession) 
  public 
     constructor Create(Owner: TComponent); 
     destructor Destroy; 

     procedure ChangeConnect(Handle : Pointer); 
     procedure SetupEnvironment;
  end; 

implementation 
uses ...;

.......

procedure TOraSess.ChangeConnect(Handle : Pointer); 
begin 
  Disconnect; 
    if (FIConnection = nil) then CreateIConnection; 

    FIConnection.Disconnect; 
    FIConnection.SetOCICallStyle(OCI80); 
    SetupEnvironment;
    FIConnection.SetSvcCtx( Handle ); 
end; 

procedure TOraSess.SetupEnvironment;
begin
  if (hOCIEnv  nil) and (OCIUnicode  IsUnicodeEnv(hOCIEnv, hOCIError)) then
    FreeOCI;
  if (Options.Direct  (PossibleOCICallStyles = [OCI80])) then begin
    FreeOCI;
    if Options.Direct then begin
      FIConnection.SetOCICallStyle(OCI80);
      InitNet;
    end
    else begin
      FreeNet;
    end;
  end;

  if not Options.Direct and (HomeName  OraCall.OracleHomeName) then begin
    FreeOCI;
    OraCall.OracleHomeName := HomeName;
  end;
end;

si2005
Posts: 3
Joined: Tue 16 Aug 2011 07:25

Post by si2005 » Wed 17 Aug 2011 10:35

Hello AlexP !

I added your changes in to my Dll, but these changes don't solve my problem (OCI_INVALID_HANDLE).

AssignConnect method also worked then session is already connected, so instead SetupEnvironment, before yor letter, i used method Connect and after, SetSvcCtx. But in my first program code i forgot to specify this

Code: Select all

    OraSess.Username := iLS3.GetFParam('USERNAME');
    OraSess.Server := iLS3.GetFParam('SERVER');
    OraSess.Password := iLS3.GetFParam('PASSWORD');
    OraSess.ConnectPrompt := false;
    OraSess.Options.Direct := true;
    OraSess.Options.Net := true;
    OraSess.Connect; // *** for initializing 
    OraSess.ChangeConnect( phSvcCtx );
Thanks again.

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

Post by AlexP » Fri 19 Aug 2011 07:50

Hello,

We have reproduced the problem.
We will notify you as soon as we have any results.

Post Reply