oracle 确定相关 tnsnames.ora 文件的位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28280883/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 00:44:30  来源:igfitidea点击:

Determining location of relevant tnsnames.ora file

oraclesqlplustoad

提问by Chad

I installed both the 32 and 64-bit Oracle 11g drivers. I search my PC looking for files with the name "tnsnames.ora" and found 3 in the following locations:

我安装了 32 位和 64 位 Oracle 11g 驱动程序。我在我的电脑上搜索名为“tnsnames.ora”的文件,并在以下位置找到了 3 个:

1. C:\Oracle\product203_32bit\CLIENT_1\NETWORK\ADMIN
2. C:\Oracle\product203_64bit\CLIENT_1\NETWORK\ADMIN
3. C:\Windows\TNS

The existence of the 3rd location of the tnsnames.ora file surprises me.

tnsnames.ora 文件的第三个位置的存在让我感到惊讶。

I have the following Oracle clients installed on my PC:

我的 PC 上安装了以下 Oracle 客户端:

"C:\Program Files (x86)\Quest Software\Toad for Oracle 11.6\Toad.exe"
"C:\Program Files\Devart\dbForge Studio Express for Oracle\dbforgeoracle.exe"

Based on the location of each program (Program Files (x86) vs. c:\Program Files), This suggests to me that the Toad, a 32 bit program, should use the 32 bit driver and dbForge should use the 64 bit driver.

根据每个程序的位置(Program Files (x86) 与 c:\Program Files),这向我建议 Toad,一个 32 位程序,应该使用 32 位驱动程序,dbForge 应该使用 64 位驱动程序。

dbForge seems to use either the tnsnames.ora file in either location #2 or #3. I know this by systematically renaming all but one of the tns files and then checking to see if the connection names read from the file are available when trying to create a new connection from with the app.

dbForge 似乎在位置 #2 或 #3 中使用 tnsnames.ora 文件。我通过系统地重命名除一个 tns 文件之外的所有文件,然后在尝试从应用程序创建新连接时检查从文件读取的连接名称是否可用来了解这一点。

However, TOAD seems to only recognize the tnsnames.ora file in location #3 and it did not recognize the tnsnames.ora file in location 2 at all! (Being that it was a 32 bit program, I did not expect it to recognize the tns file in location 2 and that was the case). TO summarize the TOAD test for the sake of hopeful clarity, TOAD only recognized the tns file in location 3.

但是,TOAD 似乎只能识别位置 #3 中的 tnsnames.ora 文件,而根本无法识别位置 2 中的 tnsnames.ora 文件!(因为它是一个 32 位程序,我没想到它会识别位置 2 中的 tns 文件,事实就是如此)。为了希望清楚起见,总结 TOAD 测试,TOAD 仅识别位置 3 中的 tns 文件。

Other colleagues do not have a tns file in location 3 on their machines. I'm not sure why I do. When I run Toad, it shows the following 2 Home, with the 32 bit Home as being the active one.

其他同事在他们机器上的位置 3 中没有 tns 文件。我不确定我为什么这样做。当我运行 Toad 时,它显示以下 2 个主页,其中 32 位主页是活动的主页。

OraClient11g_home1 (11.2.0.3)
    ORACLE_HOME:C:\app\C39293\product.2.0\client_1
    ORACLE_HOME_NAME:OraClient11g_home1
    ORACLE_HOME_KEY:HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraClient11g_home1
    ORACLE_SID:
    NLS_LANG:AMERICAN_AMERICA.WE8MSWIN1252
    SQLPATH:
    LOCAL:
    Client DLL:C:\app\C39293\product.2.0\client_1\oci.dll
    TNSNames.ora:
    SQLNet.ora:
    LDAP.ora:
    Login.sql:
    GLogin.sql:
    In system PATH:No
    Home is valid:No
OraClient11g_home1_32bit (11.2.0.3)
    ORACLE_HOME:c:\oracle\product203_32bit\CLIENT_1
    ORACLE_HOME_NAME:OraClient11g_home1_32bit
    ORACLE_HOME_KEY:HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_OraClient11g_home1_32bit
    ORACLE_SID:
    NLS_LANG:AMERICAN_AMERICA.WE8MSWIN1252
    SQLPATH:c:\oracle\product203_32bit\CLIENT_1\dbs
    LOCAL:
    Client DLL:c:\oracle\product203_32bit\CLIENT_1\bin\oci.dll
    TNSNames.ora:
    SQLNet.ora:
    LDAP.ora:
    Login.sql:
    GLogin.sql:c:\oracle\product203_32bit\CLIENT_1\sqlplus\admin\glogin.sql
    In system PATH:Yes

Q1:Is OraClient11g_home1 my 64 bit home or do I have two Oracle clients installed?

Q1:OraClient11g_home1 是我的 64 位主目录还是我安装了两个 Oracle 客户端?

Q2:Why doesn't 32 bit TOAD use the tns in location #1 instead of only using the one in location #3?

Q2:为什么 32 位 TOAD 不使用位置 #1 中的 tns 而不是仅使用位置 #3 中的 tns?

Q3:If I leave on the tns file in location 3, both dbForge and TOAD work but I'd like to know why so I can accurately understand how to move tns info from one machine to another.

Q3:如果我留在位置 3 的 tns 文件上,dbForge 和 TOAD 都可以工作,但我想知道为什么这样我可以准确地了解如何将 tns 信息从一台机器移动到另一台机器。

采纳答案by Michael S.

Just based on your paths you have two installed clients as you suspect (Toad and dbforge are tools, not clients so your terminology is a bit off). One 32-bit, the other 64-bit. It appears that Toad is 32-bit based on its installation path, but execute it and go to Help|Support Bundle. You'll see the top header will be "APPLICATION INFORMATION (32-bit)" or "APPLICATION INFORMATION (64-bit)" just to confirm. Toad 11.6 was the first to introduce a 64-bit version.

仅根据您的路径,您怀疑安装了两个客户端(Toad 和 dbforge 是工具,而不是客户端,因此您的术语有点偏离)。一个是 32 位的,另一个是 64 位的。根据其安装路径,Toad 似乎是 32 位的,但执行它并转到 Help|Support Bundle。您会看到顶部标题是“应用程序信息(32 位)”或“应用程序信息(64 位)”,只是为了确认。Toad 11.6 是第一个引入 64 位版本的版本。

Toad will only see the Oracle client that is for the same platform as it. So your 64-bit client is irrelevant for Toad's sake. The C:\Windows\TNS appears to be a folder used for TNS_ADMIN folder given its odd location and the fact that Toad sees it. At command prompt execute SET TNS_ADMIN and see if it reports "TNS_ADMIN=C:\Windows\TNS" If it does, then all Tools should be using that tnsnames.ora. That's a global override if you will that points to the folder containing your net configuration files. If you don't have TNS_ADMIN set as an environment variable then look for it in your Oracle root registry: HKEY_LOCAL_MACHINE\Software\Oracle.

Toad 只会看到与其相同平台的 Oracle 客户端。因此,您的 64 位客户端与 Toad 无关。C:\Windows\TNS 似乎是用于 TNS_ADMIN 文件夹的文件夹,因为它的位置很奇怪,而且 Toad 可以看到它。在命令提示符下执行 SET TNS_ADMIN 并查看它是否报告“TNS_ADMIN=C:\Windows\TNS” 如果是,则所有工具都应该使用该 tnsnames.ora。如果您将其指向包含网络配置文件的文件夹,则这是一个全局覆盖。如果您没有将 TNS_ADMIN 设置为环境变量,请在您的 Oracle 根注册表中查找它:HKEY_LOCAL_MACHINE\Software\Oracle。

If you use a common set of connections for all of your tools I'd delete all of your tnsnames.ora files. I'd also relocate that C:\Windows\TNS folder to somewhere more appropriate like C:\Oracle\Admin and create your tnsnames.ora, sqlnet.ora, and ldap.ora (if applicable) there. Create a TNS_ADMIN environment variable pointing to that location.

如果您为所有工具使用一组通用连接,我会删除所有 tnsnames.ora 文件。我还会将该 C:\Windows\TNS 文件夹重新定位到更合适的位置,例如 C:\Oracle\Admin,并在那里创建您的 tnsnames.ora、sqlnet.ora 和 ldap.ora(如果适用)。创建一个指向该位置的 TNS_ADMIN 环境变量。

回答by Wernfried Domscheit

According Oracle these locations are searched for tnsnames.ora, resp. sqlnet.oraand ldap.ora:

根据 Oracle 这些位置被搜索tnsnames.ora,resp。sqlnet.oraldap.ora

  1. Oracle Net files in present working directory (PWD/CWD)
  2. TNS_ADMINdefined sessionally or by user-defined script
  3. TNS_ADMINdefined as a global environment variable
  4. TNS_ADMINdefined in the registry
  5. Oracle Net files in %ORACLE_HOME/network|net80\admin(Oracle default location)
  1. 当前工作目录中的 Oracle Net 文件 (PWD/CWD)
  2. TNS_ADMIN会话定义或由用户定义的脚本
  3. TNS_ADMIN定义为全局环境变量
  4. TNS_ADMIN在注册表中定义
  5. Oracle Net 文件位于%ORACLE_HOME/network|net80\admin(Oracle 默认位置)

However, I am not sure whether each application/driver follows this list. I got this list from Oracle Document 111942.1referring to Oracle 9i, so it might be outdated.

但是,我不确定每个应用程序/驱动程序是否都遵循此列表。我从 Oracle文档 111942.1 中获得了这个列表,其中提到了 Oracle 9i,所以它可能已经过时了。

In Database Net Services Administrator's Guidethe order is

Database Net Services Administrator's Guide 中,命令是

  1. TNS_ADMINdefined by environment variable
  2. TNS_ADMINdefined in the registry (if TNS_ADMINenvironment variable is not present)
  3. %ORACLE_HOME%/network/admindirectory (if TNS_ADMINenvironment variable is not present)
  1. TNS_ADMIN由环境变量定义
  2. TNS_ADMIN在注册表中定义(如果TNS_ADMIN环境变量不存在)
  3. %ORACLE_HOME%/network/admin目录(如果TNS_ADMIN环境变量不存在)

I would recommend to define an environment variable for TNS_ADMINand use only one tnsnames.ora file. In order to be on the safe side, check also your registry values.

我建议为TNS_ADMIN一个 tnsnames.ora 文件定义一个环境变量并只使用它。为了安全起见,还请检查您的注册表值。

If your files are notlocated in %ORACLE_HOME%\network\admin, I recommend to create a symbolic link for it - just to be on the verysafe side, e.g. mklink /d %ORACLE_HOME%\network\admin c:\Oracle\common\settings\admin

如果您的文件位于%ORACLE_HOME%\network\admin,我建议创建符号链接,它-仅仅是在非常安全的一面,如mklink /d %ORACLE_HOME%\network\admin c:\Oracle\common\settings\admin

Another note, you don't have to "play" with your tnsnames.ora file. With Process Monitorfrom Microsoft Sysinternals you can monitor each file access, i.e. the filter would be Path contains tnsnames

另一个注意事项,您不必“玩”您的 tnsnames.ora 文件。使用Microsoft Sysinternals 的Process Monitor,您可以监控每个文件访问,即过滤器将是Path contains tnsnames

Update

更新

When I run a test on my machine I get following order:

当我在我的机器上运行测试时,我得到以下顺序:

  1. Environment variable TNS_ADMIN
  2. Registry Key HKEY_CURRENT_USER\SOFTWARE\ORACLE\KEY_{Oracle_Home_Name}\TNS_ADMIN
  3. Registry Key HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_{Oracle_Home_Name}\TNS_ADMIN, resp. HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE\KEY_{Oracle_Home_Name}\TNS_ADMIN

    -> Only if TNS_ADMINEnvironment variable is not set.

  4. %ORACLE_HOME%\network\admin
  5. Current directory (which can be different to directory where your application is located)
  6. Folder where your application is located
  1. 环境变量 TNS_ADMIN
  2. 注册表项 HKEY_CURRENT_USER\SOFTWARE\ORACLE\KEY_{Oracle_Home_Name}\TNS_ADMIN
  3. 注册表项HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_{Oracle_Home_Name}\TNS_ADMIN,分别。HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE\KEY_{Oracle_Home_Name}\TNS_ADMIN

    -> 仅当TNS_ADMIN未设置环境变量时。

  4. %ORACLE_HOME%\network\admin
  5. 当前目录(可能与您的应用程序所在的目录不同)
  6. 您的应用程序所在的文件夹

Update 2

更新 2

Obviously there is no fix search, it varies for different providers/drivers. Maybe it also depends on the Oracle version.

显然没有修复搜索,它因不同的提供商/驱动程序而异。也许这也取决于 Oracle 版本。

For example, the Oracle HTTP Serverreads TNS_ADMINsetting from opmn.xmlconfig file.

例如,Oracle HTTP ServerTNS_ADMINopmn.xml配置文件中读取设置。

Another example, for ODP.NET Managed Driver (Oracle.ManagedDataAccess) betaversion, I found this order at Oracle Managed and TNS Names:

另一个例子,对于 ODP.NET Managed Driver (Oracle.ManagedDataAccess)测试版,我在Oracle Managed and TNS Names找到了这个命令:

  1. data source alias in the 'dataSources' section under <oracle.manageddataaccess.client>section in the .NET config file (i.e. machine.config, web.config, user.config).
  2. data source alias in the tnsnames.orafile at the location specified by TNS_ADMINin the .NET config file.
  3. data source alias in the tnsnames.orafile present in the same directory as the .exe.
  4. data source alias in the tnsnames.orafile present at %TNS_ADMIN%
    (where %TNS_ADMIN%is an environment variable setting).
  5. data source alias in the tnsnames.orafile present at %ORACLE_HOME%\network\admin
    (where %ORACLE_HOME%is an environment variable setting).
  1. <oracle.manageddataaccess.client>.NET 配置文件部分下的“dataSources”部分中的数据源别名(即machine.config, web.config, user.config)。
  2. .NET 配置文件中tnsnames.ora指定位置的文件中的数据源别名TNS_ADMIN
  3. tnsnames.ora文件中的数据源别名与.exe.
  4. tnsnames.ora文件中存在的数据源别名%TNS_ADMIN%
    (其中%TNS_ADMIN%是环境变量设置)。
  5. tnsnames.ora文件中存在的数据源别名%ORACLE_HOME%\network\admin
    (其中%ORACLE_HOME%是环境变量设置)。

In official documentation(12c Release 4 (12.1.0.2.4)) it says:

在官方文档(12c Release 4 (12.1.0.2.4))中,它说:

  1. data source alias in the dataSourcessection under <oracle.manageddataaccess.client>section in the .NET config file (i.e. machine.config, web.config, user.config).
  2. data source alias in the tnsnames.orafile at the location specified by TNS_ADMINin the .NET config file. Locations can consist of either absolute or relative directory paths.
  3. data source alias in the tnsnames.orafile present in the same directory as the .exe.
  1. .NET 配置文件(即、、)dataSources部分下的<oracle.manageddataaccess.client>部分中的数据源别名。machine.configweb.configuser.config
  2. .NET 配置文件中tnsnames.ora指定位置的文件中的数据源别名TNS_ADMIN。位置可以由绝对或相对目录路径组成。
  3. tnsnames.ora文件中的数据源别名与.exe.

However, based on some tests I made with ODP.NET Managed Driver (4.121.2.0) it takes %ORACLE_HOME%\network\adminand TNS_ADMINEnvironment variable into account. Locks like the documentation is not 100% correct.

然而,根据一些测试我ODP.NET管理的驱动程序(4.121.2.0)需要做%ORACLE_HOME%\network\adminTNS_ADMIN环境变量考虑在内。文档之类的锁不是 100% 正确的。

回答by David Q

In case you are using Visual Studio v2017 here is tnsNames File:

如果您使用的是 Visual Studio v2017,这里是 tnsNames 文件:

32 bits installation:

32位安装:

c:\program files (x86)\oracle developer tools for vs2017\network\admin\tnsnames.ora

c:\program files (x86)\oracle developer tools for vs2017\network\admin\tnsnames.ora

64 bits installation:

64位安装:

c:\program files\oracle developer tools for vs2017\network\admin\tnsnames.ora

c:\program files\oracle developer tools for vs2017\network\admin\tnsnames.ora