Oracle TNS:网络服务名称指定不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1237610/
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-10 02:04:31  来源:igfitidea点击:

Oracle TNS: net service name is incorrecly specified

oracle

提问by John McG

Help! I'm a newbie to Oracle who's trying to access a database on an old server we inherited for a client.

帮助!我是 Oracle 的新手,他试图访问我们为客户端继承的旧服务器上的数据库。

I'm confident I have the oracle database and listener started and working, but when trying to access sqlplus or the exp commands, I'm getting the following error:

我确信我的 oracle 数据库和侦听器已启动并正常工作,但是在尝试访问 sqlplus 或 exp 命令时,出现以下错误:

ORA-12162: TNS:net service name is incorrectly specified

ORA-12162: TNS:net 服务名称指定不正确

I have edited the tnsnames.ora file to change the host to 127.0.0.1 rather than an external url and am able to successfully tnsping my connection, but am not getting much further.

我已经编辑了 tnsnames.ora 文件以将主机更改为 127.0.0.1 而不是外部 url,并且能够成功 tnsping 我的连接,但没有得到更多。

Any advice or help would be greatly appreciated.

任何建议或帮助将不胜感激。

回答by John McG

Try setting the Oracle SID

尝试设置 Oracle SID

set ORACLE_SID=database name

设置 ORACLE_SID=数据库名称

回答by Thilo

I have edited the tnsnames.ora file to change the host to 127.0.0.1 rather than an external url and am able to successfully tnsping my connection, but am not getting much further.

我已经编辑了 tnsnames.ora 文件以将主机更改为 127.0.0.1 而不是外部 url,并且能够成功 tnsping 我的连接,但没有得到更多。

The last time that happened to me (tnsping works but sqlplus does not, same error message you got), the issue was that someone had copied the tnsnames.ora file from a Windows machine, and left the wrong line feed codes in.

最后一次发生在我身上(tnsping 有效但 sqlplus 无效,您得到的错误消息相同),问题是有人从 Windows 机器复制了 tnsnames.ora 文件,并留下了错误的换行代码。

If that is the case, you need to do some dos2unix.

如果是这种情况,您需要做一些 dos2unix。

These files are verysensitive to "correct" white-space and tabbing.

这些文件对“正确”的空格和制表符非常敏感。

Someone should complain to Oracle about that.

有人应该就此向 Oracle 投诉。

回答by Dave Costa

Are you trying a local connection (e.g. "sqlplus u/p") or a network connection (e.g. "sqlplus u/[email protected]")? Are they both giving you the same error?

您是在尝试本地连接(例如“sqlplus u/p”)还是网络连接(例如“sqlplus u/[email protected]”)?他们都给你同样的错误吗?

The TNSPING by definition is using a network connection. I see some references that indicate you can get the 12612 error when using a local connection. So that is a possible explanation why you are seeing the error from SQLPlus but not TNSPING. If so, try doing a network connection instead.

TNSPING 根据定义使用网络连接。我看到一些参考资料表明您在使用本地连接时可能会收到 12612 错误。这就是为什么您看到来自 SQLPlus 而不是 TNSPING 的错误的可能解释。如果是这样,请尝试进行网络连接。

The local connection not working is probably due to ORACLE_SID not being set correctly as John suggested, but his syntax may not be the right method for whatever shell you are using. Make sure you are using the correct method for the given shell, such as "export ORACLE_SID=name" or "setenv ORACLE_SID name".

本地连接不工作可能是由于 ORACLE_SID 没有按照 John 的建议正确设置,但他的语法可能不是您使用的任何 shell 的正确方法。确保您对给定的 shell 使用了正确的方法,例如“export ORACLE_SID= name”或“setenv ORACLE_SID name”。

回答by MichaelN

Dave Costa has presented you with 2 important question. Are you trying to connect via net8 or locally via extproc? Is the listener on the local machine(127.0.0.1 -- loop back device) setup for extproc connection?

戴夫·科斯塔 (Dave Costa) 向您提出了 2 个重要问题。您是尝试通过 net8 连接还是通过 extproc 本地连接?本地机器(127.0.0.1——环回设备)上的监听器是否为 extproc 连接设置?

To use the net8 or tcp connection protocol, you need to specify user/pw@tns_alias. To connect locally via extproc you should specify the oracle_sid parameter and then connect via name/pw.

使用net8或tcp连接协议,需要指定user/pw@tns_alias。要通过 extproc 本地连接,您应该指定 oracle_sid 参数,然后通过 name/pw 连接。

I also notice the tnsalias has the .world domain appended to it, but the sqlnet.ora file does not contain a reference to NAMES.DEFAULT_DOMAIN as being "world".

我还注意到 tnsalias 附加了 .world 域,但 sqlnet.ora 文件不包含对 NAMES.DEFAULT_DOMAIN 作为“world”的引用。

Also what is the env parameter for TNS_ADMIN? Make sure your tools are looking at the correct tnsnames.ora file. Too many time people modify one tnsnames.ora and the programs/software is looking at another.

另外,TNS_ADMIN 的 env 参数是什么?确保您的工具正在查看正确的 tnsnames.ora 文件。太多时间人们修改一个 tnsnames.ora 而程序/软件正在查看另一个。

回答by Annie C

Check the tnsnames.ora file, in my case, took me days to find out there were either tab characters in the connection string or other invisible special characters that were causing it to fail.

检查 tnsnames.ora 文件,就我而言,我花了几天时间才发现连接字符串中存在制表符或其他导致它失败的不可见特殊字符。

回答by Akshay

In my case, the problem was that the DSN and the ServiceName was configured as the same in the odbc.ini file.This should not be a problem, but only after changing the DSN name, I was able to connect to the database through isql.

就我而言,问题是odbc.ini文件中的DSN和ServiceName配置为相同。这应该不是问题,但只有在更改DSN名称后,我才能通过isql连接到数据库.