I have a connection string that looks like this
con_str = "myuser/[email protected]:1521/ora1"
Where ora1
is the SID of my database. Using this information in SQL Developer works fine, meaning that I can connect and query without problems.
However, if I attempt to connect to Oracle using this string, it fails.
cx_Oracle.connect(con_str)
DatabaseError: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor
This connection string format works if the ora1
is a service name, though.
I have seen other questions that seem to have the reverse of my problem (it works with SID, but not Service name)
- Using Oracle Service Names with SQLAlachemy
- Oracle SID and Service name; connection problems
- cx_Oracle & Connecting to Oracle DB Remotely
What is the proper way to connect to Oracle, using cx_Oracle
, using an SID
and not a service name? How do I do this without the need to adjust the TNSNAMES.ORA
file? My application is distributed to many users internally and making changes to the TNSNAMES
file is less than ideal when dealing with users without administrator privileges on their Windows machines. Additionally, when I use service name, I don't need to touch this file at all and would like it keep it that way.
cx_Oracle.makedsn("oracle.sub.example.com", "1521", service_name="ora1")
, explicitly using the keywordservice_name
to differentiate it from the third argument (which issid
). – Fertile