最近看到有朋友连接数据库出现ORA-12154 、ORA-01017的异常,其实造成该异常的原因有很多,以下介绍sqlnet.ora文件中EZCONNECT参数对该异常的影响.如果想要使用EZCONNECT方式连接数据库,Windows需在客户端sqlnet.ora文件中增加“NAMES.DIRECTORY_PATH=(EZCONNECT)”信息或者删除sqlnet.ora文件.
模拟异常:
1、删除EZCONNECT
Windows客户端删除sqlnet.ora(ORACLE_HOME/network/admin目录下)中EZCONNECT参数,显示如下:
C:\Users\Administrator>sqlplus sys/oracle_4U@192.168.11.1:1521/orcl
SQL*Plus: Release 19.0.0.0.0 - Production on 星期六 7月 23 10:15:06 2022
Version 19.3.0.0.0
Copyright (c) 1982, 2019, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS: 无法解析指定的连接标识符
请输入用户名:
ERROR: ORA-01017: 用户名/口令无效; 登录被拒绝
请输入用户名:
ERROR: ORA-01017: 用户名/口令无效; 登录被拒绝
SP2-0157: 在 3 次尝试之后无法连接到 ORACLE, 退出
此时通过pl sql肯定无法连接数据库,pl sql的连接方式采用的是简易连接.
Linux系统删除服务器端EZCONNECT报错如下
[oracle@dbserver admin]$ sqlplus liujun/liujun@192.168.133.121:1521/rmlis
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Jul 23 10:41:26 2022
Version 19.12.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
ERROR:
ORA-12154: TNS:could not resolve the connect identifier specified
Enter user-name:
ERROR:
ORA-01017: invalid username/password; logon denied
Enter user-name:
ERROR:
ORA-01017: invalid username/password; logon denied
SP2-0157:
unable to CONNECT to ORACLE after 3 attempts, exiting SQL*Plus
添加上EZCONNECT,瞬间连接OK.
[oracle@dbserver admin]$ sqlplus liujun/liujun@192.168.133.121:1521/rmlis
SQL*Plus: Release 19.0.0.0.0 - Production on Sat Jul 23 10:43:23 2022
Version 19.12.0.0.0
Copyright (c) 1982, 2021, Oracle. All rights reserved.
Last Successful login time: Sat Jul 23 2022 10:38:30 +08:00
Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.12.0.0.0
说明:通过ORA-01017、ORA-12154告警,比较难想到是sqlnet.ora文件出现异常.