Getting location of file tnsnames.ora by code

后端 未结 5 1970
野的像风
野的像风 2021-02-06 08:08

How can I get the location of the tnsnames.ora file by code, in a machine with the Oracle client installed?

Is there a windows registry key indicating the l

5条回答
  •  遥遥无期
    2021-02-06 08:22

    On Windows, the most likely locations are either %ORACLE_HOME%/network/admin or %TNS_ADMIN% (or the TNS_ADMIN registry setting). These two cover almost every installation.

    Of course it is possible to have a working Oracle client without this file. Oracle has bewildering array of networking options, and there are plenty of ways to achieve a working setup with using TNSNAMES. Depending on what you are trying to achieve here, your first port of call might be the sqlnet.ora file, which is also found in %ORACLE_HOME%/network/admin. This should contain a line that looks something like this:

    NAMES.DIRECTORY_PATH= (LDAP, TNSNAMES, HOSTNAME)
    

    TNSNAMES means it will use the TNSNAMES.ora file (second in this case). LDAP and HOSTNAME are alternate ways of resolving the database. If there is no TNSNAMES the TNSNAMES.ora file will be ignored if it exists in the right place.

    In C# / .NET this should get you the environment variables:

    Environment.GetEnvironmentVariable("ORACLE_HOME");

    Environment.GetEnvironmentVariable("TNS_ADMIN");

提交回复
热议问题