1

I'm trying to connect to an oracle database with Pyodbc:

pyodbc.connect('{Microsoft ODBC for Oracle};Server=serverxzy.com:1234;Uid=myusername;Pwd=pass123')

I get the following error message:

pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

Any suggestions how to fix it would be appreciated. I'm specifically interested in getting pyodbc to work and NOT cx_Oracle.

Nickpick
  • 6,163
  • 16
  • 65
  • 116

2 Answers2

1

You have to use the proprietary library for Oracle, cx_Oracle, and you must have the Oracle client and SDK installed.

Once this is all set up you can simply:

import cx_Oracle

conn_str = 'USER/PASS@HOSTNAME:PORT/ALIAS'
conn = cx_Oracle.connect(conn_str)

Then you can create a cursor with the conn object:

c = conn.cursor()

And then you can execute SQL:

c.execute(SQL)
tadamhicks
  • 905
  • 1
  • 14
  • 34
  • 1
    If it was that simple I wouldn't have tried to switch from cx_Oracle to pyodbc. But maybe you can answer my other question in that case: http://stackoverflow.com/questions/36845401/cx-oracle-importerror-dll-load-failed-the-specified-procedure-could-not-be-fo – Nickpick Apr 25 '16 at 21:13
  • 0 Please install according to Instant Client 12.1 requirement from https://www.oracle.com/de/database/technologies/instant-client/winx64-64-downloads.html the required Visual Studio VS 2010 redistributable libraries for VS2010 SP1 and C++ https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads and bounce machine – devnull Oct 29 '20 at 19:37
1

Consider specifying the DRIVER in connection string:

pyodbc.connect('DRIVER={Microsoft ODBC for Oracle};Server=serverxzy.com:1234;
                Uid=myusername;Pwd=pass123')
Parfait
  • 104,375
  • 17
  • 94
  • 125
  • This has no impact – Nickpick Apr 26 '16 at 08:45
  • 1
    Same exact error? Check if Oracle driver is aligned to bit version of Python? ODBC drivers/DSNs can be found in ODBCcad32.exe in both: C:\Windows\System32 and C:\Windows\SysWOW64. Also, I use [pypyodbc](http://stackoverflow.com/questions/14463591/does-pyodbc-have-any-design-advantages-over-pypyodbc). – Parfait Apr 26 '16 at 13:27