oracle ORA-12162: TNS:net service name is incorrectly specified
本文将给大家阐述一个因未设置系统环境变量ORACLE_SID导致ORA-12162错误的案例。希望大家有所思考。
1.获得有关ORA-12162报错信息的通用表述信息
[oracle@asdlabdb01 ~]$ oerr ora12162
12162, 00000, "TNS:net service name is incorrectly specified"
// *Cause: The connect descriptor corresponding to the net service name in
// TNSNAMES.ORA or in the directory server (Oracle Internet Directory) is
// incorrectly specified.
// *Action: If using local naming make sure there are no syntax errors in
// the corresponding connect descriptor in the TNSNAMES.ORA file. If using
// directory naming check the information provided through the administration
// used for directory naming.
2.故障现象
本文所要描述的故障与这个通用的问题描述不同,在数据库服务器端使用TNSNAMES.ORA中记录的连接串连接没有问题,但如若未指定连接串,将会报出ORA-12162错误。
1)使用system用户尝试登录系统,此时便会收到报错如下信息
[oracle@asdlabdb01 ~]$ sqlplus system/sys
SQL*Plus:> Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
Enter user-name:
2)使用sysdba身份登陆会得到同样的错误信息
[oracle@asdlabdb01 ~]$ sqlplus / as sysdba
SQL*Plus:> Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
ERROR:
ORA-12162: TNS:net service name is incorrectly specified
Enter user-name:
3)但此时,如果使用服务名方式连接数据库,是可以成功的,这也是该问题现象的诡异之处。
[oracle@asdlabdb01 ~]$ sqlplus system/sys@ora10g
SQL*Plus:> Copyright (c) 1982, 2006, Oracle. All Rights Reserved.
Connected to: