我不断收到 pyodbc 错误。
这是我的错误:
(pyodbc.Error) ('IM012', '[IM012] [Microsoft][ODBC Driver Manager] DRIVER keyword syntax error (0) (SQLDriverConnect)')
这是我的代码:
import pyodbc
from sqlalchemy import create_engine
connection_string = (
'mssql+pyodbc://@server_name/database_name?
driver=ODBC+Driver+17+for+SQL+Server;Trusted_Connection=yes')
engine = create_engine(connection_string)
engine.connect()
如果我使用下面的命令检查我的 obdc 驱动程序,它会显示我有“ODBC Driver 17 for SQL Server”。
pyodbc.drivers()
输出:
['SQL Server',
'Microsoft Access Driver (*.mdb, *.accdb)',
'Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)',
'Microsoft Access Text Driver (*.txt, *.csv)',
'Microsoft Access dBASE Driver (*.dbf, *.ndx, *.mdx)',
'SQL Server Native Client RDA 11.0',
'ODBC Driver 17 for SQL Server']
如有任何帮助,我们将不胜感激,谢谢!我对类似问题做了一些研究,但无法找到解决方案。
查询字符串参数由
&
分隔,而不是 ;
,
connection_string = (
'mssql+pyodbc://@server_name/database_name?'
'driver=ODBC+Driver+17+for+SQL+Server&Trusted_Connection=yes'
)