pyodbc.connect - 在一台计算机上工作,但在另一台计算机上不工作

pyodbc.connect - works from one computer but not another

我已经 运行 Python 脚本使用我的桌面在工作中成功连接到远程桌面服务器并通过 pyodbc.connect 在 SQL 中输出数据。

我希望将此代码迁移到最近在工作中安装的单独的远程桌面 PC,但出现以下错误:

InterfaceError: ('IM002', '[IM002] [Microsoft][ODBC Driver Manager] 未找到数据源名称且未指定默认驱动程序 (0) (SQLDriverConnect)')

我使用的代码是:

cnxn = pyodbc.connect("Driver={SQL Server Native Client 11.0};"
                  "Server=AUBAMTRAS01-DEV;"
                  "Database=ForwardTrading;"
                  "Username=xxxxxxxx;"
                  "Password=yyyyyyyy;"
                  "Trusted_Connection=yes;")

cursor = cnxn.cursor()
cursor.execute('SELECT distinct(Commodity) from ForwardCurvesOilAndGas')

for row in cursor:
    print('row = %r' % (row,))

Data source name not found and no default driver specified

这意味着您需要在第二台机器上安装 SQLDriverConnect 驱动程序。

已解决 - 所需的驱动程序是 'SQL Server' 而不是 'SQL Server Native Client 11.0'