2

Hey I'm not sure what is wrong with this connection string, i'm getting the error - pyodbc.Error: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

here is my script:

import pyodbc
conn_str = (
    "DRIVER={PostgreSQL ANSI};"
    "DATABASE=postgres;"
    "UID=postgres;"
    "PWD=password;"
    "SERVER=localhost;"
    "PORT=5432;"
    )
conn = pyodbc.connect(conn_str)
crsr = conn.execute("SELECT * FROM initialdata limit 50")
row = crsr.fetchone()
print(row)
crsr.close()
conn.close()

and here is my ODBCINST.INI file contents:

[PostgreSQL ANSI(x64) (32 bit)]
Driver=C:\Program Files\psqlODBC\0905\bin\psqlodbc30a.dll
Setup=C:\Program Files\psqlODBC\0905\bin\psqlodbc30a.dll
32Bit=1

[ODBC 32 bit Drivers]
PostgreSQL ANSI(x64) (32 bit)=Installed
PostgreSQL Unicode(x64) (32 bit)=Installed

[PostgreSQL Unicode(x64) (32 bit)]
Driver=C:\Program Files\psqlODBC\0905\bin\psqlodbc35w.dll
Setup=C:\Program Files\psqlODBC\0905\bin\psqlodbc35w.dll
32Bit=1

Any help would be appreciated!

2
  • 1
    Based on the odbcinst.ini file it looks like your driver name should be: PostgreSQL ANSI(x64) (32 bit) ... not just PostgreSQL ANSI Commented Mar 25, 2016 at 3:53
  • 1
    What does the name look like in your ODBC Data Source Administrator (odbcad32.exe), Drivers tab. Also... it looks like you're running 32bit drivers on a 64bit machine. Is your python 32 or 64 bit? It should match the drivers that you installed. Commented Mar 25, 2016 at 4:01

1 Answer 1

4

check list of drivers by using pyodbc.drivers() and use driver name from it

the driver name should be like PostgreSQL ANSI(x64) instead of PostgreSQL ANSI.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.