why system login is denied in cx_Oracle.SYSDBA mod

2019-08-05 17:31发布

问题:

I am trying to connect to Oracle 12c through cx_Oracle module. Login using following code works where no mode is mentioned in cx_Oracle.connect method

import cx_Oracle                                                                
ip = 'ip'                                                             
port='1521'                                                                    
SID='orcl'                                                                     
dsn_tns = cx_Oracle.makedsn(ip, port, SID)                                     
db = cx_Oracle.connect('system', 'password', dsn_tns)

but for following way it shows invalid login error for cx_Oracle.SYSDBA mode.

db = cx_Oracle.connect('system', 'password', dsn_tns, cx_Oracle.SYSDBA) 

Error:

cx_Oracle.DatabaseError: ORA-01017: invalid username/password; logon denied

What am I missing here ?? credentials are same. I tried login manually as follows and is successful

>sqlplus system/password as sysdba

回答1:

If you connect as user sys, you need to use the cx_Oracle.SYSDBA mode:

conn = cx_Oracle.connect('sys', 'password', dsn_tns, cx_Oracle.SYSDBA)
ok

conn = cx_Oracle.connect('sys', 'password', dsn_tns)
ORA-28009: connection as SYS should be as SYSDBA or SYSOPER

However, if you connect as user system, you mustn't use the cx_Oracle.SYSDBA mode:

conn = cx_Oracle.connect('system', 'password', dsn_tns)
ok

conn = cx_Oracle.connect('system', 'password', dsn_tns, cx_Oracle.SYSDBA)
ORA-01017: invalid username/password; logon denied

The difference of the users sys and system is explained for instance here.