Connect OpenEdge database with 'pyodbc'


Below prerequisite must be meet, before try example code:

1.'pyodbc' package is installed pip install pyodbc1

2.You have OpenEdge DB service running on local or remote:
DB Service

3.OpenEdge ODBC Driver is installed:
ODBC Driver

Example Code

Below example code made a connection to OpenEdge's sport database and query 'Department' table with SQL:

import pyodbc

# The driver name 'Progress OpenEdge 11.6 Driver' maps to the OE ODBC driver you've installed
cnxn = pyodbc.connect('DRIVER={Progress OpenEdge 11.6 Driver};HostName=localhost;DATABASENAME=sport;PORTNUMBER=5678;LogonID=[db_id];PASSWORD=[password]')

# Return a new Cursor object
cursor = cnxn.cursor()  
cursor.execute("select * from PUB.Department")

# Fetch the next set of rows of a query result, returning a list of Row instances. 
# An empty list is returned when no more rows are available.
rows = cursor.fetchall()

for row in rows:  

Here's the results:Return Results

  1. When I try install 'pyodbc' on windows, get error message "Unable to find vcvarsall.bat". This is because pip looks for some C compiler to compile 'pyodbc' from source code, and your windows don't have any compiler installed. The workaround can be found here