Skip to content
Advertisement

Can’t connect Sqlalchemy with pyodbc to SQL Server 2000

I followed this website by installing

Install:
sudo apt-get install freetds-dev freetds-bin unixodbc-dev tdsodbc
pip install pyodbc sqlalchemy
In /etc/odbcinst.ini:

[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsS.so

After install I try this code and it worked, it print all records from table2

import pyodbc

conn = pyodbc.connect('DRIVER=FreeTDS;SERVER=<IP_OR_HOSTNAME>;PORT=1433;DATABASE=<DATABASE_NAME>;UID=<USERNAME>;PWD=<PASSWORD>;TDS_Version=8.0;')
cursor = conn.cursor()
for row in cursor.execute('SELECT * FROM Table2'):
    print (row)

However, I want to use SQLAlchemy with pyodbc and it does not work

import urllib

from sqlalchemy import create_engine


engine = create_engine('mssql+pyodbc:///?odbc_connect=' +
    urllib.parse.quote_plus('DRIVER=FreeTDS;SERVER=<IP_OR_HOSTNAME>;PORT=1433;DATABASE=<DATABASE_NAME>;UID=<USERNAME>;PWD=<PASSWORD>;TDS_Version=8.0;')
)
for row in engine.execute('SELECT * FROM Table2'):
    print (row)

ProgrammingError: (pyodbc.ProgrammingError) (‘42000′, “[42000] [FreeTDS][SQL Server]’schema_name’ is not a recognized function name. (195) (SQLExecDirectW)”) [SQL: SELECT schema_name()] (Background on this error at: https://sqlalche.me/e/14/f405)

How can I connect this?

Advertisement

Answer

SQLAlchemy 1.4 does not support SQL Server 2000. Use pip install sqlalchemy==1.3.24.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement