1

I am using this code to connect with oracle database:

import cx_Oracle

conn_str = u"jbdc:oracle:thin:@****_***.**.com"
conn = cx_Oracle.connect(conn_str)
c = conn.cursor()

However, I am getting this error:

ORA-12560: TNS:protocol adapter error

How can I resolve it?

Thank you

1 Answers1

1

You cannot use a JDBC thin connect string to connect with cx_Oracle (or the new python-oracledb). You must use either an alias found in a tnsnames.ora file, or the full connect descriptor (such as that found in a tnsnames.ora) file or an EZ+ Connect string. An example follows:

conn_str = "user/password@host:port/service_name"

With the new python-oracledb driver you can also do this:

import oracledb
conn = oracledb.connect(user="USER", password="PASSWORD", host="my_host",
                        port=1521, service_name="my_service")

See the documentation for more details.

Anthony Tuininga
  • 6,388
  • 2
  • 14
  • 23
  • Thanks! Where can I find tnsnames.ora for SQL Squirrel? – Python-data Nov 28 '22 at 18:27
  • The environment variable $TNS_ADMIN points to the location of that file, or it is found in certain default locations. The documentation link I gave above shows this. Here is a more direct link: https://python-oracledb.readthedocs.io/en/latest/user_guide/initialization.html#optnetfiles – Anthony Tuininga Nov 28 '22 at 20:39