I have the failover database connection Some thing like below:
CONSTR =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Host Name)(PORT = Port Number))
(LOAD_BALANCE = YES)
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = Service Name)
(FAILOVER_MODE =
(TYPE = SELECT)
(METHOD = BASIC)
(RETRIES = 180)
(DELAY = 5)
Is it possible to establish oracle connection in python using cx_Oracle imports.
using python 3.5
currently using
con = cx_Oracle.connect(user="myuser", password="mypass", dsn=dsnStr)
to connect the db.
and below statement returns the CONSTR (as mentioned above)
dsnStr = cx_Oracle.makedsn("hostName", "port", "SIDNAME")
My requirement is to directly use the CONSTR (with failover URL) in cx_Oracle.connect().
As noted by the documentation the third parameter is for the SID. If you are intending to use a SERVICE_NAME you need to do the following instead:
dsnStr = cx_Oracle.makedsn("hostName", "port", service_name="service_name")
If you have defined something in your tnsnames.ora file, however, you can just that name directly. You don't have to use makedsn().
Also, you can use EZ connect syntax as in the following:
cx_Oracle.connect("user/pw@host:port/service_name")
Hopefully one of those options will help you out!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With