cx_Oracle.DatabaseError:ORA-12514:TNS:侦听器当前不知道连接描述符

时间:2017-10-29 21:38:41

标签: python linux oracle database-connection cx-oracle

我正在尝试从Python程序对新安装的Oracle client 12.2 in RHEL 7 linux进行完整性测试,但是由于上述错误而失败,不确定我在那里缺少什么。请帮忙解决这个问题:

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

tnsnames.ora目录下的/home文件

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

,我的python程序在

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

frdld2d1.de.db.com - IP地址: 10.245.63.34

感谢是否有人指出这里的故障。

tnsping实用程序无法测试,因为它是一个instaclient版本

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

但是使用SQLPlus,我可以毫无问题地连接数据库。

2 个答案:

答案 0 :(得分:5)

请使用此作为您的连接字符串:

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

SERVICE_NAME = FRDLD2D1文件中将SID = FRDLD2D1更改为TNSNAMES.ORA可能是另一种选择。

答案 1 :(得分:1)

您只需在没有配置文件(tnsnames.ora)的python中创建dsn

dsn = cx_Oracle.makedsn(host='10.245.63.34', port=1825, sid='FRDLD2D1')
con = cx_Oracle.connect(user='PNTH_LOGGINGB_OWNER', password='password', dsn=dsn)