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

标签 python linux oracle database-connection cx-oracle

我正在尝试通过 Python 程序对 RHEL 7 linux 中新安装的 Oracle 客户端 12.2 进行健全性测试,但它因上述错误而失败,不确定我在那里遗漏了什么。请帮助解决这个问题:

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,我可以毫无问题地连接数据库。

最佳答案

请将其用作您的连接字符串:

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

TNSNAMES.ORA 文件中将 SID = FRDLD2D1 更改为 SERVICE_NAME = FRDLD2D1 可能是一种替代方法。

关于python - cx_Oracle.DatabaseError : ORA-12514: TNS:listener does not currently know of service requested in connect descriptor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47005505/

相关文章:

oracle - DBMS_LOCK 在过程中抛出错误,即必须声明标识符

Python:互相导入

python - Android SL4A (Python) 强制停止包失败。

python - sqlalchemy.exc.ArgumentError : Mapper mapped class could not assemble any primary key columns for mapped table 'users'

python - Geopy 在 ASCII 字符上阻塞

java - 有效期控制程序

linux - C# 资源暂时不可用,在 linux 上的 dotnet core 上阻塞套接字

linux - i386 :x64-32 vs i386 vs i386:x86_64 之间的区别

java.lang.IllegalStateException : The driver is not executable:/resources/phantomjs-2. 1.1-linux-x86_64/bin/phantomjs

Oracle - Materialized View,这个MV可以快速刷新吗?