Bug: TOraServerEnumerator does not check TNS_ADMIN environment variable

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
jdorlon
Posts: 202
Joined: Fri 05 Jan 2007 22:07

Bug: TOraServerEnumerator does not check TNS_ADMIN environment variable

Post by jdorlon » Thu 26 Aug 2021 14:02

Hello,

The subject says it all. TOraServerEnumerator.GetServerList does not look for TNS_ADMIN environment variable.

Thanks

John

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Bug: TOraServerEnumerator does not check TNS_ADMIN environment variable

Post by MaximG » Fri 27 Aug 2021 08:50

Yes, the variable TNS_ADMIN is not referenced in TOraServerEnumerator.GetServerList, but is referenced earlier, in the TOracleHomes class in the OracleCall unit: procedure AddToOracleHomes(const Path, Key: string; ClientType: OralceClientType);

jdorlon
Posts: 202
Joined: Fri 05 Jan 2007 22:07

Re: Bug: TOraServerEnumerator does not check TNS_ADMIN environment variable

Post by jdorlon » Fri 27 Aug 2021 13:28

Well, when I tried it (using an instant client, so no network\admin folder in my oracle home), it didn't find my tnsnames file, which can only be found using the TNS_ADMIN environment variable.

My code is like this, (where cboDatabase is a TCombobox)

Code: Select all

var
  Enum: TOraServerEnumerator;
begin
  Enum := TOraServerEnumerator.Create;
  try
    Enum.GetServerList(cboDatabase.Items);
  finally
    Enum.Free;
  end;
Is the code not intended to be used this way?

-John

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

Re: Bug: TOraServerEnumerator does not check TNS_ADMIN environment variable

Post by MaximG » Fri 03 Sep 2021 13:12

Hi John!

Thanks for your reply.

The code you provided will return a list of TNS aliases for only one default ORACLE_HOME.
In this case, you can explicitly assign the default ORACLE_HOME. For example, if the Oracle InstantClient you installed is
located in the 'C:\OracleInstantClient' folder, and the TNS_ADMIN = C:\OracleInstantClient\NETWORK\ADMIN, you can change your code as follows:

Code: Select all

uses OraCall;
....

var
  Enum: TOraServerEnumerator;
begin
  Enum := TOraServerEnumerator.Create;
  try
    OracleHomes.AddHome('MyInstantClient', 'C:\OracleInstantClient');
    OracleHomes.Default := OracleHomes.GetHome('MyInstantClient');
    Enum.GetServerList(cboDatabase.Items);
  finally
    Enum.Free;
  end;
end;

jdorlon
Posts: 202
Joined: Fri 05 Jan 2007 22:07

Re: Bug: TOraServerEnumerator does not check TNS_ADMIN environment variable

Post by jdorlon » Fri 03 Sep 2021 13:15

ok, thanks Maxim.

lanikane68
Posts: 1
Joined: Tue 12 Jul 2022 04:06

Re: Bug: TOraServerEnumerator does not check TNS_ADMIN environment variable

Post by lanikane68 » Tue 12 Jul 2022 04:15

Your article is very good and informative, I always follow your article. You are an author that I love. Thank you for sharing! moviedle

Post Reply