使用SQLAlchemy连接到数据库

2024-05-26 11:10:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试连接到本地计算机上的数据库。

import sqlalchemy
engine = sqlalchemy.create_engine('mssql+pyodbc://localhost\\SQLEXPRESS/NCM')

失败,错误如下:

DBAPIError: (pyodbc.Error) ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (0) (SQLDriverConnect)')

并输出此警告:

C:\Miniconda\envs\bees\lib\site-packages\sqlalchemy\connectors\pyodbc.py:82: SAWarning: No driver name specified; this is expected by PyODBC when using DSN-less connections
"No driver name specified; "

我应该在哪里诊断这个问题?


Tags: nonameimport数据库localhostsqlalchemydriver计算机
1条回答
网友
1楼 · 发布于 2024-05-26 11:10:51

this link所示,从1.0.0版起,您需要显式指定主机名连接的驱动程序。

Changed in version 1.0.0: Hostname-based PyODBC connections now require the
SQL Server driver name specified explicitly. SQLAlchemy cannot choose an 
optimal default here as it varies based on platform and installed drivers.

相关问题 更多 >