ORA-01017 When Connect SYSDBA by SQL Developer

on

在尝试使用SQL Developer用SYSDBA连接数据库时总是报ORA-01017错误。

ORA-01017: invalid username/password; logon denied

实际上用户名密码是正确的,并且在数据库服务器上使用SQL*Plus通过监听连接也是正常的。

[sourcecode language=”sql” light=”true”]C:\Users\Kamus>sqlplus "sys/oracle@orcl11g as sysdba"

SQL*Plus: Release 11.1.0.7.0 – Production on Fri Mar 12 12:17:01 2010

Copyright (c) 1982, 2008, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 – Production
With the Partitioning, OLAP and Real Application Testing options

SQL> [/sourcecode]

真正的问题是因为数据库密码文件缺失了。在windows下,Oracle数据库密码文件是储存在%ORACLE_HOME%\database目录下,命名为PWD%SID%.ora。

密码文件不存在,数据库实例完全可以正常启动,只是在尝试通过监听登陆SYSDBA的时候就会报ORA-01017错误。

那么为什么在本地使用SQL*Plus是正常的,这实际上是一个错觉,因为在Windows中Oracle默认安装以后会在sqlnet.ora文件中设置SQLNET.AUTHENTICATION_SERVICES = (NTS),这表示支持“Windows NT native authentication”方式登陆数据库,也就是属于OSDBA组的Windows用户不用提供密码也可以通过SYSDBA登陆数据库。sqlnet.ora文件位于%ORACLE_HOME%\network\admin目录下。

我们随便使用一个不存在的用户名密码都是可以登录数据库的。

[sourcecode language=”sql” light=”true”]C:\Users\Kamus>sqlplus "NotExist/nopassword@orcl11g as sysdba"

SQL*Plus: Release 11.1.0.7.0 – Production on Fri Mar 12 13:10:49 2010

Copyright (c) 1982, 2008, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 – Production
With the Partitioning, OLAP and Real Application Testing options

SQL>[/sourcecode]

修改SQLNET.AUTHENTICATION_SERVICES参数为NONE之后。

SQLNET.AUTHENTICATION_SERVICES = (NONE)

再次测试用SQL*Plus登陆,报ORA-01031错误,即使提供正确的SYS用户密码也会报同样的错误,因为此时密码文件不存在,不能通过密码文件校验SYS用户密码是否正确,而又不允许通过NTS方式登陆数据库。

[sourcecode language=”sql” light=”true”]C:\Users\Kamus>sqlplus "NotExist/nopassword@orcl11g as sysdba"

SQL*Plus: Release 11.1.0.7.0 – Production on Fri Mar 12 13:14:07 2010

Copyright (c) 1982, 2008, Oracle. All rights reserved.

ERROR:
ORA-01031: insufficient privileges

Enter user-name:[/sourcecode]

重新创建密码文件,保持sqlnet.ora文件中SQLNET.AUTHENTICATION_SERVICES = (NONE)。

orapwd file=D:\oracle\product\11.1.0\db_1\database\PWDorcl11g.ora password=oracle

这样就只能通过正确的SYS用户和密码才可以用SYSDBA登陆数据库了。

[sourcecode language=”sql” light=”true”]C:\Users\Kamus>sqlplus / as sysdba

SQL*Plus: Release 11.1.0.7.0 – Production on Fri Mar 12 13:18:32 2010

Copyright (c) 1982, 2008, Oracle. All rights reserved.

ERROR:
ORA-01031: insufficient privileges

Enter user-name:
C:\Users\Kamus>
C:\Users\Kamus>sqlplus sys/oracle as sysdba

SQL*Plus: Release 11.1.0.7.0 – Production on Fri Mar 12 13:18:44 2010

Copyright (c) 1982, 2008, Oracle. All rights reserved.

Connected to:
Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 – Production
With the Partitioning, OLAP and Real Application Testing options

SQL>[/sourcecode]

同样在这种配置下,SQL Developer也可以正常用SYSDBA登陆数据库了。

6 Comments Add yours

  1. Peter says:

    “重新创建密码文件,保持sqlnet.ora文件中SQLNET.AUTHENTICATION_SERVICES = (NONE)。”
    怎么个重新创建方法?谢谢~

  2. Kamus says:

    orapwd,回车,可以看到语法

  3. xy says:

    这个问题弄的我快哭了
    试一下

  4. xy says:

    貌似我不是这个问题
    目录下面已经有这个文件了

  5. Kamus says:

    @xy
    有这个文件,并不一定其中的密码记录和数据库中的一样,你可以尝试重新创建pwd文件。

  6. qiang says:

    重新创建是出现OPW-00001:无法打开口令文件 应该如何处理啊

Leave a Reply to Peter Cancel reply

Your email address will not be published. Required fields are marked *