前几天在RedHat AS 4.1上安装Oracle 10G ,在创建数据库的过程中始终报告:
ORA-12154: TNS:could not resolve service name。 不知道为什么这样,然后就到网上到处搜索解决办法。每一种可能想到的原因试了,Oracle 10G装了不下10词,那天晚上我忙活到凌晨2点。所有可能想到的原因都试了一遍。昨天晚上又作最后的挣扎,那个痛苦真的无法形容。有时候解决问题的办法,是瞬间的事情,你说是从石头缝里蹦出来的也可以。总之那也是无法形容的幸福。好说了半天没有把事情的本质告诉大家。
那就是Oracle用户的密码千万不要含有"@"字符。虽然这个世界上绝大部分Oracle数据库工具包括第三方的软件都不会拒绝密码含有"@"字符的用户连接,但是SQLPLUS却拒绝了。后来我想想原因可能是SQLPLUS错误地解析了连接串中的TNSName.
例如:你有一个TNSName是SZVW1047, 设定System的密码为I@SUZHOU
现用SQLPLUS 连接:
SQL> conn system@szvw1047
Enter password:
ERROR:
ORA-12154: TNS:could not resolve service name
Warning: You are no longer connected to ORACLE.
他是怎么错误的解析了,我的猜想是SQLPLUS将用户密码和system@szvw1047 连接在一起:system/I@SUZHOU@szvw1047 然后执行conn system/I@SUZHOU@szvw1047,结果sqlplus分析出的tnsname为"SUZHOU@szvw1047",密码为"I",这时候当然报告could not resolve service name。 下面是我重新更改system密码为"hello"后的连接情况:
SQL> conn system@szvw1047
Enter password:
ERROR:
ORA-12154: TNS:could not resolve service name
SQL> conn /@szvw1047 as sysdba
Connected.
SQL> alter user system identified by "hello"
2 /
User altered.
SQL> conn system@szvw1047
Enter password:
Connected.
SQL>
那事实又是怎样的呢,为了探清事实的真相,我在SQLNET.ORA添加了两行,以便跟踪客户端的连接:
TRACE_LEVEL_CLIENT = ADMIN
TRACE_DIRECTORY_CLIENT = /Client
这两行的含义是打开客户的跟踪,并将跟踪信息写到/Client,接着作了下面的动作:
SQL> conn system@szvw1047
Enter password:
ERROR:
ORA-12154: TNS:could not resolve service name
查看跟踪文件,截取一段如下:
nnfgrne: Going though read path adapters
nnfgrne: Switching to DCE adapter
nnfgrne: Original name: SUZHOU
nnfgrne: Name did not qualify, skipping to next adapter
nnfgrne: Switching to CDS adapter
nnfgrne: Original name: SUZHOU
nnfgrne: Name did not qualify, skipping to next adapter
nnfgrne: Switching to TNSNAMES adapter
nnfgrne: Original name: SUZHOU
nnftqnm: entry
nnfcagmd: entry
nnfcagmd: Attribute name a.smd is a predefined meta type, syntax is 4.
nnfcagmd: exit
nnfgrne: Query unsuccessful, skipping to next adapter
nnfgrne: Switching to ONAMES adapter
nnfgrne: Original name: SUZHOU
nngtnms_new_msg: new message, ID 26752, type 100
nngtnms_new_msg: initial message pool block, size 2
nngtrms_release_msg: entry
nngtrms_release_msg: exit
nnfgrne: Query unsuccessful, skipping to next adapter
nnfgrne: Switching to ONRS adapter
nnfgrne: Original name: SUZHOU
nngtnms_new_msg: new message, ID 26753, type 100
nngtrms_release_msg: entry
nngtrms_release_msg: exit
nnfgrne: Query unsuccessful, skipping to next adapter
nnfgrne: Switching to HOSTNAME adapter
nnfgrne: Original name: SUZHOU
nnfhqnm: entry
nnfcagmd: entry
nnfcagmd: Attribute name a.smd is a predefined meta type, syntax is 4.
nnfcagmd: exit
从这个文件可以看出与我的想象差别不大,只不过分析出来的名称不是SUZHOU@szvw1047,而是SUZHOU.
真的让人意想不到,Oracle竟然犯这种低级错误。