名称为...的游标已存在 - SQL Server 2008 [英] A cursor with the name ... already exists - SQL Server 2008

查看:1441
本文介绍了名称为...的游标已存在 - SQL Server 2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个触发器,用于在对表进行更改时执行一些审核任务。在这个触发器中有一个WHILE循环,在循环中有一个游标,在循环的下一次迭代之前被声明,使用,关闭和释放。

I have a trigger that is used to perform some auditing tasks when changes are made to a table. Within this trigger there is a WHILE loop, and in the loop there is a cursor that is declared, used, closed and then deallocated before the next iteration of the loop.

当我调用一个存储过程来改变表,进而导致触发器运行时,我从Management Studio中这样做,所有的工作原理。

When I call a stored procedure that changes the table and in turn causes the trigger to run, and I do this from within the Management Studio, all works as expected.

但是,当这个存储过程从我的Java Web应用程序中调用时,我收到一个错误:一个游标名为...已经存在。

However, when this stored procedure is called from within my Java web application, I get an error: "A cursor with the name ... already exists".

为什么这个存储过程在我手动执行时会起作用,而当从Web应用程序运行时不起作用。

Is there a reason why this stored procedure would work when I execute it manually, and not work when run from the web application?

推荐答案

如果必须使用游标:

如果可以,在所有代码中使用LOCAL游标。
例如使用LOCAL关键字声明游标,如下所示:

If you can, use LOCAL cursors in all your code. e.g. declare cursor using the "LOCAL" keyword, like this:

DECLARE yourcursor CURSOR LOCAL ...

这篇关于名称为...的游标已存在 - SQL Server 2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆