A trigger returned a resultset and/or was running with SET NOCOUNT OFF while another outstanding result set was active

懵懂的女人 提交于 2019-12-03 22:59:35

The trigger is returning a "resultset" of sorts, the number of rows affected. "(1 row(s) affected) // or n rows...." I don't know why this is being interpreted as a resultset but it is.

I had a similar issue today and I realized that this issue can be fixed by putting a SET NOCOUNT OFF towards the end of the trigger. Just having the SET NOCOUNT ON at the top of the trigger is not sufficient.

The trigger in which I am referring is the pre-made "insert" statement in your application.This is most likely the statement throwing the SQL error.

Now you can use sp_configure 'disallow results from triggers' 1, but, that will disable this for the entire database and that may not be desirable, in case you are expecting some other trigger to return a resultset.

The OP of the Source I used described the exact same problem you are having if my answer doesn't suffice. Also, MSDN had said

The ability to return result sets from triggers will be removed in a future version of SQL Server. Avoid returning result sets from triggers in new development work, and plan to modify applications that currently do this. To prevent triggers from returning result sets in SQL Server 2005, set the disallow results from triggers Option to 1. The default setting of this option will be 1 in a future version of SQL Server.

I got the same issue and have a solution.

The problem was a stored-procedures with a result set, which was executed in this trigger.

It seems, that this stored-procedure leads the trigger to have a result set as well.

Rodrigo Ruiz

I had the same problem.

The problem was an insert with select:

insert into table (...)
select ...

The problem was that select had a group statements and returned:

Warning: Null value is eliminated by an aggregate or other SET operation.

this causing the problem, I changed instructions max(field) by max(coalesce(field,'')) to avoid the null operation in max group function.

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