PyODBC 中的存储过程写道:并非所有参数都在字符串格式化期间转换

Stored procedure in PyODBC writes: not all arguments converted during string formatting

我有这个代码:

with connections["mssql_database"].cursor() as cursor:
                sql = "EXEC SaveActivity @id_workplace=?, @personal_number=?, @id_activity=?"
                params = (id_workplace, personal_number, id_activity)
                cursor.execute(sql, params)


TypeError: not all arguments converted during string formatting

当我尝试时

cursor.callproc("SaveActivity", [id_workplace, personal_number, id_activity])

它写道:

AttributeError: 'pyodbc.Cursor' object has no attribute 'callproc'

发生此错误是因为您传递的参数与 SQL 服务器中数据库端定义的类型不匹配。

@id_workplace@personal_number@id_activity 都是整数吗?如果是这样,Python 变量 id_workplacepersonal_numberid_activity 是否都是整数? Python 变量的值是多少?如果其中任何一个是 None,您需要确保相应的数据库变量允许 NULL.