Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python cx_Oracle connection with failover oracle url

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().

like image 759
Tim Avatar asked Jul 15 '26 09:07

Tim


1 Answers

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!

like image 50
Anthony Tuininga Avatar answered Jul 18 '26 01:07

Anthony Tuininga