从MS SQL服务器使用Python获取数据时出错 [英] Error fetching data with Python from MS SQL server

查看:281
本文介绍了从MS SQL服务器使用Python获取数据时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从MS SQL获取一个表,但是我收到错误:

编程错误:('ODBC SQL类型-151尚不支持.column-index = 3 type = -151 ','HY106')



有什么想法吗?



我尝试了什么:



I need to get a table from MS SQL, but I get the error:
ProgrammingError: ('ODBC SQL type -151 is not yet supported. column-index=3 type=-151', 'HY106')

Any idea?

What I have tried:

import pyodbc

cnxn = pyodbc.connect("Driver={ODBC Driver 13 for SQL Server};"
                      "Server=localhost;"
                      "Database=AdventureWorks2012;"
                      "Trusted_Connection=yes;")
cursor = cnxn.cursor()
cursor.execute('SELECT * FROM HumanResources.Employee')

row = cursor.fetchone()
while row:
    print (row[0])
    row = cursor.fetchone()

推荐答案

您的Python驱动程序不支持被称为-151的ODBC SQL类型(我无法找到这背后的实际类型是什么)所以它不能只读取表格,所以你需要添加一个输出转换器,类型为-151,因此驱动程序知道如何处理它。以下是输出转换器的示例,您可以将其转换为您的类型所需的内容:使用输出转换器函数·mkleehammer / pyodbc Wiki·GitHub [ ^ ]
Your Python driver does not support the ODBC SQL type that's referred to as "-151" (I could not find what the actual type behind this is) so it can't just read the table, so you'll need to add an output converter for the type -151 so the driver knows what to do with it. Here's an example for an Output Converter, you can transform it into what you need for your type: Using an Output Converter function · mkleehammer/pyodbc Wiki · GitHub[^]


这篇关于从MS SQL服务器使用Python获取数据时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆