我正在尝试将 pyodbc 连接切换到 sqlalchemy。工作的 pyodbc 连接是:
import pyodbc
con = 'DRIVER={ODBC Driver 11 for SQL Server};SERVER=server.com\pro;DATABASE=DBase;Trusted_Connection=yes'
cnxn = pyodbc.connect(con)
cursor = cnxn.cursor()
query = "Select * from table"
cursor.execute(query)
Run Code Online (Sandbox Code Playgroud)
我试过:
from sqlalchemy import create_engine
dns = 'mssql+pyodbc://server.com\pro/DBase?driver=SQL+Server'
engine = create_engine(dns)
engine.execute('Select * from table').fetchall()
Run Code Online (Sandbox Code Playgroud)
基于: http: //docs.sqlalchemy.org/en/latest/core/engines.html
并且:使用 SQLAlchemy 时 pandas.read_sql() 比 pyodbc 慢得多
(尝试使用 Trusted_Connection = Yes 建立连接)
但我收到消息:
操作错误:(pyodbc.OperationalError) ('08001','[08001] [Microsoft][ODBC SQL Server 驱动程序][DBNETLIB]不存在 SQL Server 服务,无法访问。 (17) (SQLDriverConnect); [08001] [Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()).(53)') (此错误的背景位于: http: …