Why the output parameter of my ADODB.Command does not retrieve a value when executing?

旧城冷巷雨未停 提交于 2019-12-01 11:08:30
Lankymart

As @diana has already pointed out you cannot access the output parameter because it isn't set until the query has executed.

This is a common problem and in this case you might think but I'm not executing a query that returns any results, I'm just inserting some data?

At first glance this may appear to be the case but when you take into consideration the use of

Select @msg_salida = '1'

you are in fact returning a single row single column ADODB.Recordset object.

In these instances using SET instead of SELECT is advisable because it does not create a ADODB.Recordset or block access to the OUTPUT parameters until all ADODB.Recordset objects are closed.

By changing the above line for example to

SET @msg_salida = '1'

and changing your ADODB.Command execute to

'Execute the command without returning any Recordsets
Call cmd2.Execute()
d89761

As the answer on Why adParamOutput parameter doesn't contain a value after execute explains:

You have to iterate through all records before you can read the output parameter, like

do until rs.EOF
     rs.MoveNext
loop

In my case the issue was nothing to do with record sets being retrieved. Check if On Error Resume Next is being used in the Classic ASP script as there could be an MSSQL exception being swallowed that is causing the output parameter to never be set.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!