oracle / python-cx_Oracle

Python interface to Oracle Database now superseded by python-oracledb
https://oracle.github.io/python-cx_Oracle
Other
890 stars 361 forks source link

Protocol for cx_Oracle.makedsn #619

Closed hvardhan20 closed 2 years ago

hvardhan20 commented 2 years ago
  1. What versions are you using?

8.3.0

  1. Describe the problem

Is there a protocol argument for cx_Oracle.makedsn function? It is forming the DSN string with TCP by default and there is no way to change that. Is there? I would like to specify TCPS as the protocol while using cx_Oracle.makedsn. How can I do that?

  1. Include a runnable Python script that shows the problem.
import cx_Oracle
dsn_tns = cx_Oracle.makedsn(host, port, SID)

Thanks!

anthony-tuininga commented 2 years ago

There is no way, currently, to specify the protocol within makedsn(). You can use an easy connect string to accomplish the task, though:

dsn = "tcps://host:port/service_name"

If you have the separate components you can do this:

dsn = f"{protocol}://{host}:{port}/{service_name}"

The ability to build connect strings in a more generic and complete fashion (and yes, including the protocol) will be forthcoming in a new version. Stay tuned!

cjbj commented 2 years ago

For completeness you can also pass a full connect descriptor with protocol, or put the connect descriptor in a tnsnames.ora file and pass the descriptor alias when you connect:

cjdbmelb = (description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)... etc etc

See the doc on Connection Strings.

hvardhan20 commented 2 years ago

Thanks for the clarification! Will go with the f-string for now.