oracle 如何使用 tnsnames.ora 连接 SQLPlus
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41377699/
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
How to connect SQLPlus with tnsnames.ora
提问by KamilK
I want to connect with my Oracle database withoutinstalling Oracle Client.
我想在不安装 Oracle 客户端的情况下连接到我的 Oracle 数据库。
I downloaded:
我下载了:
- "Instant Client Package - Basic" and
- "Instant Client Package - SQL*Plus"
- “即时客户端包 - 基本”和
- “即时客户端包 - SQL*Plus”
Then I created folder on C:\Oracle\instantclient
, where I extracted all packages.
然后我在 上创建了文件夹C:\Oracle\instantclient
,在那里我提取了所有包。
I have been set system environment
like:
我被设置system environment
为:
Path - C:\Oracle\instantclient
NSL_LANG - with properly key
ORACLE_HOME - C:\Oracle\instantclient
ORACLE_SID - C:\Oracle\instantclient
TNS_ADMIN - C:\Oracle\instantclient
Path - C:\Oracle\instantclient
NSL_LANG - with properly key
ORACLE_HOME - C:\Oracle\instantclient
ORACLE_SID - C:\Oracle\instantclient
TNS_ADMIN - C:\Oracle\instantclient
Then I created tnsnames.ora
file with configuration in C:\Oracle\instantclient
然后我创建tnsnames.ora
了配置文件C:\Oracle\instantclient
and when I puted a command to cmd:
当我向 cmd 发出命令时:
sqlplus user/password @HOST
sqlplus user/password @HOST
I have a message like:
我有一条消息,如:
ERROR:
ORA-12560: TNS:protocol adapter error
ERROR:
ORA-12560: TNS:protocol adapter error
but when I tried like:
但是当我尝试像:
sqlplus user/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=address to host)(Port=1521))(CONNECT_DATA=(SID=address to SID)))
sqlplus user/password@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=address to host)(Port=1521))(CONNECT_DATA=(SID=address to SID)))
everything works properly. Why SQL have a problem with recognize tnsnames.ora file?
一切正常。为什么 SQL 识别 tnsnames.ora 文件有问题?
采纳答案by Alex Poole
Your command should be:
你的命令应该是:
sqlplus user/password@HOST
with no space between the password and @HOST
part.
密码和@HOST
部分之间没有空格。
With the space it treats the @HOST
as a script to execute once you've logged in, and it tries to connect locally, which produced that TNS error. (As you don't log in the HOST
isn't ever evaluated to establish if it exists, so it's effectively noise at this point).
有了空间,它会在@HOST
您登录后将其视为要执行的脚本,并尝试在本地连接,从而产生了 TNS 错误。(由于您没有登录,因此HOST
永远不会评估以确定它是否存在,因此此时它实际上是噪音)。
C:\>sqlplus -l -s x/y @HOST
ERROR:
ORA-12560: TNS:protocol adapter error
SP2-0751: Unable to connect to Oracle. Exiting SQL*Plus
With the space removed it looks for HOST
as a TNS alias:
删除空间后,它会查找HOST
TNS 别名:
C:\>sqlplus -l -s x/y@HOST
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
SP2-0751: Unable to connect to Oracle. Exiting SQL*Plus
For me that still gets an error since I don't have HOST
in my tnsnames.ora
, but it's a different error and you can see it's at least trying to use it as a TNS alias. If you have it defined properly it will be able to connect to your database.
对我来说,那仍然得到一个错误,因为我没有HOST
在我的tnsnames.ora
,但它是一个不同的错误,你可以看到它至少尝试使用它作为一个TNS别名。如果您正确定义了它,它将能够连接到您的数据库。
回答by yxh
NEVER edit $ORACLE_HOME/network/admin/tnsname.ora manually, use "netmr" to create Local Name. Don't know why it's same but do not work.
切勿手动编辑 $ORACLE_HOME/network/admin/tnsname.ora,使用“netmr”创建本地名称。不知道为什么它相同但不起作用。