简体   繁体   中英

how to handle "ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA" in python database connectivity

I have written the below code as a practice on PDBC

import cx_Oracle
con=cx_Oracle.connect('scott/tiger@localhost')
if con:
    print("success..")
    con.close()
else:
    print("error")

and I got below error

DatabaseError: ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA

please help me to sort it out

con should be modified so that it contains some more info: port and service name

con = cx_Oracle.connect('scott/tiger@localhost:1521/service_name')
                                               ----
                                               port

Port usually is 1521 ; service name depends on what you chose. If it is an Oracle XE (Express edition), might be xe . Ask your DBA.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM