无法将 Sqlalchemy 与 pyodbc 连接到 SQL Server 2000
Can't connect Sqlalchemy with pyodbc to SQL Server 2000
我按照这个 website 安装了
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
安装后我尝试了这段代码,它成功了,它打印了 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)
但是,我想将 SQLAlchemy 与 pyodbc 一起使用,但它不起作用
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)
我该如何连接它?
SQLAlchemy 1.4 不支持 SQL Server 2000。请使用 pip install sqlalchemy==1.3.24
.
我按照这个 website 安装了
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
安装后我尝试了这段代码,它成功了,它打印了 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)
但是,我想将 SQLAlchemy 与 pyodbc 一起使用,但它不起作用
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)
我该如何连接它?
SQLAlchemy 1.4 不支持 SQL Server 2000。请使用 pip install sqlalchemy==1.3.24
.