3

im trying to make a connection to an as400 with db2 using pyodbc and the ibm db2 odbc driver.

import pyodbc

connection = pyodbc.connect(
    driver='{IBM DB2 ODBC DRIVER}',
    system='192.168.1.100',
    uid='user',
    pwd='pass')
c1 = connection.cursor()

#this is meaningless sql, i just want the connection
c1.execute('select * from libname.filename')
for row in c1:
    print (row)

Running this gives me this error

python pydata.py

Traceback (most recent call last):
  File "C:\Users\tca\Desktop\ScriptingSTuff\pydata.py", line 3, in <module>
    connection = pyodbc.connect(
pyodbc.OperationalError: ('08001', '[08001] [IBM][CLI Driver] SQL1013N  The database alias name or database name "" could not be found.  SQLSTATE=42705\r\n (-1013) (SQLDriverConnect)')

Any ideas?

This is all under win10

EDIT: Adding this "database='s10c38ft',"

import pyodbc

connection = pyodbc.connect(
    driver='{IBM DB2 ODBC DRIVER}',
    system='192.168.1.100,8471',
    database='s10c38ft',
    uid='user',
    pwd='pass')
c1 = connection.cursor()

c1.execute('select * from libname.filename')
for row in c1:
    print (row)

Makes it hang on a blinking cursor, I cant even CTRL+C to end it, I have to close cmd.

1
  • 1
    Check the documentation for the ODBC driver. Supplying the port number by comma-appending it to the server name/IP (e.g., 192.168.1.100,8471) is something that I've only ever seen for Microsoft's ODBC drivers for SQL Server. Most other ODBC drivers use a separate SERVER= and PORT= arguments. Commented Jun 11, 2021 at 18:42

1 Answer 1

8

The proper driver name should be IBM i Access ODBC Driver (but see notes below). Other than that, your first example was correct:

connection = pyodbc.connect(
    driver='{IBM i Access ODBC Driver}',
    system='192.168.1.100',
    uid='user',
    pwd='pass')

If that doesn't work, there are two main possibilities:

  1. You are using an old ODBC driver. This would happen if you are using the old iSeries Access (in which case the driver name is iSeries Access ODBC Driver) or even older Client Access (driver name Client Access ODBC Driver (32-bit)). If you choose the appropriate name for your driver, it will work.

  2. You are using an ODBC driver that is not for IBM i. The most commonly used member of the Db2 family is Db2 for LUW (Linux, Unix, Windows), but there are others. None of these will work for you.

You can find out the list of exact ODBC driver names you have installed by calling pyodbc.drivers(). If you don't have any of the ones I mentioned above by name, then you don't have the right driver. The ODBC driver you want is the one described here.

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

6 Comments

When I try that I get this error. "pyodbc.InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')"
@Anthony - Check the list returned by pyodbc.drivers() to see what ODBC drivers are available to your Python app.
>>> print(pyodbc.drivers()) ['SQL Server', 'IBM DB2 ODBC DRIVER - IBMDBCL1', 'IBM DB2 ODBC DRIVER', 'IBM DB2 ODBC DRIVER - C_PROGRA~1_IBM_CLIDRI~1', '
Where did you get that driver? I have never heard of it. Do you maybe have a driver for Db2 for LUW?
Heres the link I got it from ibm.com/support/pages/…
|

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.