1

I am using a standard cx_Oracle.connect() statement in python like this

cnxn = cx_Oracle.connect(user/pwd@connection:port/service)

And I am getting this error

DatabaseError: ORA-12170: TNS:Connect timeout occurred

I think it is because we just switch to a amazon/aws/rds database, which is very slow, and the connection is timing out too soon. Is there a simple way to increase the wait until the timeout occurs?

I tried these solutions with no success so far.

cx_Oracle Connection Timeout

https://github.com/oracle/python-cx_Oracle/issues/277

bart cubrich
  • 1,184
  • 1
  • 14
  • 41
  • Answer below but could be any number of things. Make sure you can connect feom dbeaver etc. Make sure the syntax is correct. Sometimes cx will try to connect with wrong details and still give a timeout error – EoinS May 16 '22 at 23:54
  • Yes, I cannot connect with dbeaver either. I am going to look into some other possibilities, but my question still stands as written I think. – bart cubrich May 17 '22 at 15:39

2 Answers2

2

If you are using Oracle Client 19c or later, you can add a connect timeout to your Easy Connect string. See Oracle Database 21c Easy Connect Plus:

cnxn = cx_Oracle.connect(user/pwd@connection:port/service?transport_connect_timeout=15)

There is also a connect_timeout option, see the tech brief link above for the difference.

Christopher Jones
  • 9,449
  • 3
  • 24
  • 48
1

You probably dont have a timeout with cx_oracle but rather with your oracle client

You can call_timeout but typically for requests after initial connection.

You can update your sqlnet.ora file as below

SQLNET.INBOUND_CONNECT_TIMEOUT = 0

Similar so question

cx_oralce Docs

EoinS
  • 5,405
  • 1
  • 19
  • 32