I am trying to connect to Oracle db using pyodbc, getting errors. The examples include ms sql server driver:
in my /etc/unixODBC/odbc.ini, I have this entry:
[test_con]
Driver=Oracle
Description=data repository db
Trace=Yes
ServerName=//db1.example.com:1521/db2_svc1
import pyodbc
cnxn=pyodbc.connect('DSN=test_con, UID=user_id, PWD=passwd123')
I get this error:
pyodbc.Error: ('IM012', '[IM012] [unixODBC][Driver Manager]DRIVER keyword syntax error (0) (SQLDriverConnect)')
By this command, you can install cx-Oracle package but it is required to install Oracle database first on your PC. connect(): Now Establish a connection between the Python program and Oracle database by using connect() function.
The ODBC driver has Oracle's standard client-server version interoperability, see Support Doc ID 207303.1. For example Instant Client ODBC 19c can connect to Oracle Database 11.2 or later.
I came here looking for an answer to this question, but instead found an answer elsewhere to a more general question that I'd like to share. You can very simply connect to an Oracle db without pyodbc, using the cx_Oracle library. Check out the installation instructions below:
https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html
Starter code below:
cx_Oracle.init_oracle_client(lib_dir=r"C:\oracle\instantclient_19_10")
connection = cx_Oracle.connect(
user="username",
password="password",
dsn="address")
cursor = connection.cursor()
pyodbc maintainer did an excellent job at documenting how to install Oracle ODBC driver and then how to connect to the database. It worked for me: https://github.com/mkleehammer/pyodbc/wiki/Connecting-to-Oracle-from-RHEL-or-Centos
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With