user8108863
user8108863

Reputation:

How to fix cx_Oracle.DatabaseError: ORA-12514: TNS:listener error

I use python 3.6 (32bit) and I use Oracle database 11g, I want to connect my python to oracle database. This is my version oracle for python cx-Oracle==7.2.1

This is my file.ORA :

myservice = (DESCRIPTION=
(ADDRESS=
    (PROTOCOL=tcp)
    (HOST=localhost)
    (PORT= ))
(CONNECT_DATA=
    (SERVICE_NAME=orcl)))

This is My Code:

import cx_Oracle
con= cx_Oracle.connect("db_employees/root@localhost/orcl")
cur= conn.cursor()
cur.execute('select*from employess')
for line in cur:
    print(line)
cur.close()
con.close()

But it shows errors. This is my errors messages:

C:\Python36>python "D:\bisa.py"
Traceback (most recent call last):
File "D:\bisa.py", line 3, in <module>
     con= cx_Oracle.connect("db_employees/root@localhost/orcl")
cx_Oracle.DatabaseError: ORA-12514: TNS:listener does

How to fix this error?

Upvotes: 0

Views: 979

Answers (1)

Popeye
Popeye

Reputation: 35920

Try this in .ORA file

myservice =
   (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = <<validhostname>>)(PORT = <<validportnumber>>))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = <<servicenameofDB>>)
    )
)

Upvotes: 1

Related Questions