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

我在使用python连接oracle12.2.2的时候,报以下错误:
cx_Oracle.DatabaseError: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
译为:
cx_Oracle.DatabaseError: ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务

我的oracle是在远程服务器上使用docker-compose安装的,在服务器和客户端都可以连接成功,但是在python程序连接cx_oracle时报错
查询网上资料好多有如下两种解决方案:
1.通过重启服务的方式启动数据库,再次连接服务器;
2.考虑监听listener.ora

SID_LIST_LISTENER =
  (SID_LIST =
    (SID_DESC =
      (SID_NAME = PLSExtProc)
      (ORACLE_HOME = E:\Oracle10g)
      (PROGRAM = extproc)
    )
    #此处是添加部分,ORCL为监听的实例名
   (SID_DESC =
    (GLOBAL_DBNAME = ORCL)
    (ORACLE_HOME = E:\Oracle10g)
    (SID_NAME = ORCL)
    )
    ##
 )

LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
      (ADDRESS = (PROTOCOL = TCP)(HOST = onest)(PORT = 1521))
    )
  )

3.第三种方案:
以上两种对我都不管用,最后我发现连接python连接cx_oracle时,要用SERVICE_NAME,而不是sid
至于原因,应该是当前处于Oracle的并行环境,一个数据库对应多个实例,这样就需要多个网络服务名,设置繁琐。为了方便并行环境中的设置,引进了service_name参数,该参数对应一个数据库,而不是一个实例。
首先,在用管理员账号登陆oracle,查询SERVICE_NAME:

select value from v$parameter where name like '%service_name%';

cx_Oracle.DatabaseError: ORA-12514: TNS:listener does not currently know of service requested in con_第1张图片
其次,将查询到的service_name替换sid即可
如:

pool = PooledDB(cx_Oracle, user = "trump", password = "123456", dsn = "192.168.1.12:1523/EE.oracle.docker",mincached=2,maxcached=2,maxshared=2,maxconnections=2)

启动成功!

你可能感兴趣的:(python,Oracle)