使用 PYODBC 将一定数量的参数传递给存储过程时出错

error when passing with certain number of parameters to stored procedure using PYODBC

希望有人可以帮助我解决以下问题: 我正在从 Python - 3.8.3 - 使用以下代码调用存储过程

def set_param_days(self, cursor, valueWW):
    # valueWW = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', 
                '17', '18', '19', '20', '21', '22', '23', '24', '25']
    query = 'exec [dbo].[SetOUTPUT] @dInervals=%s' % (valueWW,)
    cursor.execute(query)

然而,当执行此代码时,我收到以下错误:

cursor.execute(query)
pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]The identifier that starts with ''1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23',' is too long. Maximum length is 128. (103) (SQLExecDirectW)")

最初,我认为错误与 SQL 服务器中的存储过程有关,但经过进一步测试,我将存储过程名称完全更改为 none 现有的并收到相同的确切的错误,意味着该错误与 PYODBC 或 python 代码有关 - 调用从未到达 SQL server-

重要:如果参数的数量不超过 23,代码将完全没有问题地执行!

query = 'exec [dbo].[SetOUTPUT] @dInervals=\'%s\'' % ",".join(valueWW)