我想执行该过程并获取输出参数
import pypyodbc
command = "DECLARE @l_Stat INT \r\n" \
"DECLARE @s_Ms VARCHAR(200) \r\n" \
"EXEC p_Log_InsertParam_2011v1 " \
"@l_TesterId=?, " \
"@l_ObiektId=?, " \
"@l_RejPId=?, " \
"@s_ParamName=?, " \
"@f_ParamValue=?, " \
"@f_ParamMinValue=?, " \
"@f_ParamMaxValue=?, " \
"@b_CheckParam=?, " \
"@l_Status=@l_Stat output, " \
"@s_Msg=@s_Ms output \r\n" \
"SELECT @l_Stat, @s_Ms\r\n"
connection = pypyodbc.connect(self.ConnectionString)
cursor = connection.cursor()
params=(453879185, 23192812, 645872, '/APL/CTRL_GZ/PID/SP', 35.0, 0, 0, True)
# params = (testerid,
# obiektid,
# rejpid,
# paramname,
# paramvalue,
# paramminvalue,
# parammaxvalue,
# checkparam) """
result = cursor.execute(command, params)
pars = result.fetchall()[0]
print pars
if pars.__len__() >= 2:
l_status = pars[0]
s_msg = pars[1]
print "{}: {};".format(l_status, s_msg)
它可以很好地运行到行result = cursor.execute(command, params)
- 程序正确执行。
当我尝试在行pars = result.fetchall()[0]
中获取结果时出现问题:
u'24000', u'[24000] [Microsoft][ODBC SQL Server Driver]Invalid Cursor State'
如何摆脱这个错误?
答案 0 :(得分:3)
当p_Log_InsertParam_2011v1
存储过程不
SET NOCOUNT ON;
作为其第一个可执行语句。当我在存储过程开始时添加它时,错误就消失了。