我正在尝试从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
,我可以毫无问题地连接数据库。
答案 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)