I'm trying to connect to a Pervasive database using pyodbc. Below is the code I've tried:
import pyodbc
server = '10.10.10.01'
database = 'RMS'
username = 'test'
password = 'test123'
conn = pyodbc.connect(f'DRIVER=Pervasive ODBC Interface;SERVER={server};'
f'DBQ={database};UID={username};PWD={password}')
cursor = conn.cursor()
When executing I receive the following error:
pyodbc.OperationalError: ('08S01', '[08S01] [Zen][ODBC Client Interface][Client LNA]Connection attempt timed out. The SQL Connection Manager may be inactive or using a different transport protocol from the client. (10065) (SQLDriverConnect); [08S01] [Zen][ODBC Client Interface]Invalid connection string attribute. (0)')
I've seen some examples online where they are connecting not using a username/password. I've tried this as well, but still receive the same error. The database is active as I am able to make an OLE DB connection successfully from another application.
Anyone see what I'm doing wrong?
After trying it on a Windows machine connecting to another Windows machine, there might be a problem with the connection string. I kept getting an error 161 error ( [Zen][ODBC Client Interface][LNA][Zen][SQL Engine][Data Record Manager]A key has reached a maximum limit for user count, session count, or data in use, or has changed state to expired or disabled.(Btrieve Error 161)). Once I changed the connection string from SERVER=
to SERVERNAME=
, it started working for me.
So, my test file that worked was:
import pyodbc
server = 'PSQLSERVERNAME'
database = 'DEMODATA'
username = 'test'
password = 'test123'
conn = pyodbc.connect(f'DRIVER=Pervasive ODBC Interface;SERVERNAME={server};DBQ={database};UID={username};PWD={password}')
cursor = conn.cursor()
cursor.execute("SELECT * FROM CLASS;")
row = cursor.fetchone()
while row:
print(row[0])
row = cursor.fetchone()
You'll want to change the servername, database name, and the SQL query.