I managed to install Oracle 12.2.01, running its official Docker image on 64bit Linux with:
docker run --name oracle12-se2 -p 1521:1521 -p 5500:5500 -e ORACLE_PWD=my_pwd oracle/database:12.2.0.1-se2
The database seems to be running correctly, I can enter its SQL > prompt with:
docker exec -ti oracle12-se2 sqlplus system@ORCLPDB1
and issue commands there.
But trying to connect from another Linux machine via Python's pyodbc fails. I'm using the official Oracle Instant Client + ODBC driver 19.3, but I got lost in all the acronyms: DBQ, SID, DSN, TSN, instance, SERVER_NAME, tnsnames.ora, ports… None of the following work:
import pyodbc # version 4.0.26
conn_params = [
{'server': '175.201.160.29:1521', 'uid': 'system', 'pwd': 'my_pwd', 'driver': "Oracle 19 ODBC driver"},
{'server': '175.201.160.29:1521/ORCLCDB', 'uid': 'system', 'pwd': 'my_pwd', 'driver': "Oracle 19 ODBC driver"},
{'server': '175.201.160.29:1521/ORCLPDB1', 'uid': 'system', 'pwd': 'my_pwd', 'driver': "Oracle 19 ODBC driver"},
{'dbq': '175.201.160.29:1521', 'uid': 'system', 'pwd': 'my_pwd', 'driver': "Oracle 19 ODBC driver"},
{'dbq': '175.201.160.29:1521/ORCLCDB', 'uid': 'system', 'pwd': 'my_pwd', 'driver': "Oracle 19 ODBC driver"},
{'dbq': '175.201.160.29:1521/ORCLPDB1', 'uid': 'system', 'pwd': 'my_pwd', 'driver': "Oracle 19 ODBC driver"},
]
for attempt in conn_params:
try:
conn = pyodbc.connect(**attempt)
print('SUCCESS!')
except Exception:
print('failed with', attempt)
The error is always Error: ('IM004', "[IM004] [unixODBC][Driver Manager]Driver's SQLAllocHandle on SQL_HANDLE_HENV failed (0) (SQLDriverConnect)"). How to debug this?
EDIT: I made some progress. I can successfully connect to the remote database using cx-oracle instead of pyodbc:
import cx_Oracle
connection = cx_Oracle.connect("system", "my_pwd", "175.201.160.29/ORCLPDB1")
# …connection cursors work as expected, all good
I guess that verifies there is no issue with the database or connectivity as such. However, I need pyodbc to work, not cx-oracle, so my question above still stands.
odbc_update_ini.shand symlinked all shared libs. Where do I get thistnsnames.ora, what do I put in it, and how do I configure pyodbc after that? The official docs are completely opaque to me.tsnnames.orafile by hand. It seems to work. I'll post it as an answer, see if it makes any sense or I'm completely off.