cx_Oracle.DatabaseError: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor

Vijay picture Vijay · Oct 29, 2017 · Viewed 8k times · Source

I am trying to do a sanity testing of newly installed Oracle client 12.2 in RHEL 7 linux from a Python program, but it fails with the above error, not sure what I am missing on there. Please help with this case :

cx_Oracle.DatabaseError: ORA-12514: TNS:listener does not currently know of service 
requested in connect descriptor

my tnsnames.ora file under /home directory

  FRDLD2D1 =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(Host = frdld2d1.de.db.com)(Port = 1825))
    )
    (CONNECT_DATA =
      (SID = FRDLD2D1)
      )
   )

and my python program goes below

#!/usr/bin/python
import cx_Oracle
#connection = cx_Oracle.connect('PNTH_LOGGINGB_OWNER/password')
connection = cx_Oracle.connect('PNTH_LOGGINGB_OWNER/[email protected]:1825/orcl')
cursor = connection.cursor()
querystring = "select * from BDR_JOB_MASTER_LOG where ROWNUM <= 1;"
cursor.execute(querystring)

frdld2d1.de.db.com - IP address : 10.245.63.34

Appreciate if any points the glitch on here.

tnsping utility is not there to test since it is an instaclient version

oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64.rpm.

But with SQLPlus, I am able to connect the database without any issues.

Answer

Barbaros &#214;zhan picture Barbaros Özhan · Oct 29, 2017

Please use this as your connection string :

connection = cx_Oracle.connect('PNTH_LOGGINGB_OWNER', 'hdgf_76trf', 
                                cx_Oracle.makedsn('10.245.63.34',1825,'FRDLD2D1') );

Changing SID = FRDLD2D1 to SERVICE_NAME = FRDLD2D1 in your TNSNAMES.ORA file may be an alternative.