将状态信息从存储过程传递给事务内的调用者
我有一个长时间运行的 SP(它可以运行长达几分钟),它基本上对事务中的各个表执行大量清理操作。我正在尝试确定以某种方式将人类可读的状态信息传递回调用者的最佳方法,以了解 SP 当前正在执行的流程的哪一步。
因为整个 SP 在单个事务中运行,所以我无法将此信息写回状态表,然后从另一个线程读取它,除非我使用 NOLOCK 来读取它,我认为这是最后的手段,因为:
- NOLOCK 可能会导致其他数据不一致问题;这
- 使得任何想要读取状态表的人都需要使用 NOLOCK,因为表或行可能会被锁定很长一段时间。
有没有办法在事务中发出单个命令(或执行第二个 SP)并告诉指定该特定命令不应成为事务的一部分?或者 ADO.NET 是否有其他方法可以深入了解这个长期运行的 SP 以了解它当前正在做什么?
I have a long-running SP (it can run for up to several minutes) that basically performs a number of cleanup operations on various tables within a transaction. I'm trying to determine the best way to somehow pass human-readable status information back to the caller on what step of the process the SP is currently performing.
Because the entire SP runs inside a single transaction, I can't write this information back to a status table and then read it from another thread unless I use NOLOCK to read it, which I consider a last resort since:
- NOLOCK can cause other data inconsistency issues; and
- this places the onus on anyone wanting to read the status table that they need to use NOLOCK because the table or row(s) could be locked for quite a while.
Is there any way to issue a single command (or EXEC a second SP) within a transaction and tell specify that that particular command shouldn't be part of the transaction? Or is there some other way for ADO.NET to gain insight into this long-running SP to see what it is currently doing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在 T-SQL 中打印消息,并通过“InfoMessage”事件将它们传递到 ADO.NET 中的 SqlConnection。请参阅
http://msdn.microsoft.com/en-us/library/a0hee08w。 aspx
了解详细信息。
You can PRINT messages in T-SQL and get them delivered to your SqlConnection in ADO.NET via the "InfoMessage" event. See
http://msdn.microsoft.com/en-us/library/a0hee08w.aspx
for details.
您可以尝试使用 RAISERROR (使用 10 或更低的严重性)返回信息性消息的过程。
例子:
You could try using RAISERROR (use a severity of 10 or lower) within the procedure to return informational messages.
Example: