Page 1 of 1

pOciSvcCtx

Posted: Tue 16 Aug 2011 09:06
by si2005
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;

Posted: Tue 16 Aug 2011 13:46
by AlexP
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\)

Posted: Wed 17 Aug 2011 05:19
by si2005
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.

Posted: Wed 17 Aug 2011 09:22
by AlexP
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;

Posted: Wed 17 Aug 2011 10:35
by si2005
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.

Posted: Fri 19 Aug 2011 07:50
by AlexP
Hello,

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