v$session.program not populating

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ccedotal
Posts: 9
Joined: Tue 05 Jul 2011 16:42

v$session.program not populating

Post by ccedotal » Wed 21 Aug 2013 13:58

We have OCAC 9.0.1 for Delphi7. When the application connects, v$session.program is NULL. Application security checks fail when this value is not the name of the executing program. Please advise.

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

Re: v$session.program not populating

Post by AlexP » Wed 21 Aug 2013 14:59

Hello,

We cannot reproduce the problem. The v$session view returns the correct application name. Please try executing the following code on the latest ODAC version, if the code returns errors - contact us again.

Code: Select all

program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils,
  Windows,
  Ora;

const
  UserName = 'SYS';
  Passwd = 'PASSWORD';

var
  OraSession: TOraSession;
  Buffer: array [0..MAX_COMPUTERNAME_LENGTH + 1] of AnsiChar;
  len: Cardinal;
begin
  len := MAX_COMPUTERNAME_LENGTH + 1;
  GetComputerName(Buffer, len);

  OraSession := TOraSession.Create(nil);
  try
    OraSession.Connect('Data Source=ORCL1120;User ID=' + UserName + ';Password=' + UserName + ';Connect Mode=cmSysDBA');
    OraSession.ExecSQL('BEGIN'#13#10 +
                       'SELECT PROGRAM INTO :ProgramName'#13#10 +
                       '  FROM V$SESSION'#13#10 +
                       '    WHERE TERMINAL = :Terminal'#13#10 +
                       '    AND SCHEMANAME = :Schema;'#13#10 +
                       'EXCEPTION'#13#10 +
                       '  WHEN TOO_MANY_ROWS THEN RAISE_APPLICATION_ERROR(-20001, ''More than one application is running'');'#13#10 +
                       '  WHEN NO_DATA_FOUND THEN RAISE_APPLICATION_ERROR(-20001, ''No application is not running'');'#13#10 +
                       '  WHEN OTHERS THEN RAISE_APPLICATION_ERROR(-20001, ''Other errors'');'#13#10 +
                       'END;',['', string(Buffer), UserName]);
    Assert(ExtractFileName(ParamStr(0)) =  OraSession.ParamByName('ProgramName').AsString);
    Writeln(Format('Application Name : %s == V$SESSION.PROGRAM : %s',[ExtractFileName(ParamStr(0)), OraSession.ParamByName('ProgramName').AsString]));
  finally
    OraSession.Free;
    readln;
  end;
end.

Post Reply