'pyodbc.Cursor'对象没有属性'fast_executemany'

问题描述 投票:0回答:1

我有一个问题,我有一个正在使用的网络应用程序

fast_executemany
以便插入到数据库中。当在本地主机上运行它时,它可以正常工作,但是当将它部署到 Azure 时,我得到了

'pyodbc.Cursor'
对象没有属性
'fast_executemany'

我正在使用

  • Python 2.7
  • AZURE SQL 服务器数据库
  • pyodbc==4.0.24

Web 应用程序存储在 Azure 中

python azure azure-sql-database pyodbc
1个回答
0
投票

Azure 为我们提供了如何使用 Python 连接 Azure SQL 数据库以及使用 Transact-SQL 语句查询数据的教程。

如果我们想使用

fast_executemany
属性,我们必须设置
cursor.fast_executemany = True

我们可以这样修改示例:

import pyodbc
server = '<server>.database.windows.net'
database = '<database>'
username = '<username>'
password = '<password>'
driver= '{ODBC Driver 17 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password)
cursor = cnxn.cursor()
cursor.fast_executemany = True
cursor.execute("SELECT TOP 20 pc.Name as CategoryName, p.name as ProductName FROM [SalesLT].[ProductCategory] pc JOIN [SalesLT].[Product] p ON pc.productcategoryid = p.productcategoryid")
row = cursor.fetchone()
while row:
    print (str(row[0]) + " " + str(row[1]))
    row = cursor.fetchone()

我想你可以再试一次。如果您还有其他问题,请告诉我,我会尽力帮助您。

希望这可以帮助你。

© www.soinside.com 2019 - 2024. All rights reserved.