首页 > 解决方案 > 存储过程 - 游标状态无效

问题描述

我正在尝试运行存储过程,但我收到以下错误。我尝试做 AutoCommit = True 但仍然没有运气。

错误:

pypyodbc.ProgrammingError: ('24000', '[24000] [Microsoft][ODBC SQL Server Driver]Invalid cursor state')

代码

 def sqlConnection():
conn = pypyodbc.connect('Driver={SQL Server};''Server=test;''Database=test;'
                        'Trusted_Connection=yes;autocommit=True')

cursor = conn.cursor()


return conn, cursor

def payments(cursor, conn):
    cd = datetime.today()
    formatted_date = datetime.strftime(cd, "%m/%d/%Y")

     payments_q = """\
        EXEC pRptMonTrTypeSumm @jobkey=?, @cdate=?
        """
      params = (1, '08/30/2020')
      fpl_payments_results = cursor.execute(payments_q, params)

       for row in payments_results.fetchall():
       payments3 = row[4]
       print(payments3)

标签: python

解决方案


SET NOCOUNT ON;在存储过程之前尝试。


推荐阅读