简体   繁体   English

在 cx_oracle 上使用多个主机

[英]Using multiple hosts on cx_oracle

I'm using the cx_oracle pip package to connect to a oracle DB at work.我正在使用 cx_oracle pip 包连接到工作中的 oracle 数据库。

dsn_tns = cx_Oracle.makedsn('1.2.3.4', '1521', service_name='TRADES')
conn = cx_Oracle.connect(user='analytics_user', password='welcome', dsn=dsn_tns)
c = conn.cursor()
c.execute('SELECT * FROM all_tables')

However the oracle db I connect to has 2 host IP addresses.但是,我连接的 oracle db 有 2 个主机 IP 地址。

The original connection string I was given was like this;我得到的原始连接字符串是这样的;

SERVICE  =
   (DESCRIPTION =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 1.2.3.4)(Port=1521))
     (ADDRESS = (PROTOCOL = TCP)(HOST = 1.222.33.44)(Port=1521))
     (CONNECT_DATA =
       (SERVICE_NAME = TRADES)
     )
   )

Is there anyway to use both on cx_oracle?无论如何都可以在 cx_oracle 上使用两者? or is there any other package I can use that will allow that?或者我可以使用任何其他包来允许吗? SQL_Alchemy? SQL_Alchemy?

you can use the DSN string as is, without the SERVICE = :您可以按原样使用 DSN 字符串,而无需SERVICE =

DSN = """
   (DESCRIPTION =
     (ADDRESS = (PROTOCOL = TCP)(HOST = 1.2.3.4)(Port=1521))
     (ADDRESS = (PROTOCOL = TCP)(HOST = 1.222.33.44)(Port=1521))
     (CONNECT_DATA =
       (SERVICE_NAME = TRADES)
     )
   )
"""

with cx_Oracle.connect(user='user', password='pass', dsn=dsn_tns) as conn:
    c = conn.cursor()
    c.execute('SELECT * FROM all_tables')

thanks @Christopher-Jones here the details oracle-net-connect-descriptor-strings感谢@Christopher-Jones 这里的细节oracle-net-connect-descriptor-strings

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM