我拔掉客户端工作站的插头,长时间运行的数据库进程会发生什么?
可能的重复:
SQL Server 和中间的连接丢失交易
我有一个 .NET 3.5 客户端应用程序,它在 MS SQL Server 2005 上启动一个长时间运行的(5-10 m)存储过程。该存储过程以 BEGIN 开头TRAN
并以 COMMIT TRAN
结尾。
如果我拔掉工作站的插头,存储过程会发生什么情况,它是否会完成运行?它在所有情况下都能完成运行吗?或者与工作站的连接丢失是否会导致数据库中止存储过程?
编辑:工作站和 SQL Server 位于不同的盒子上。
Possible Duplicate:
SQL Server and connection loss in the middle of a transaction
I have a .NET 3.5 client app that kicks off a long-running (5-10 m) stored proc on the MS SQL Server 2005. The stored proc starts with BEGIN TRAN
and ends with COMMIT TRAN
.
If I pull the plug on the workstation, what happens to the stored procedure, does it finish running? Does it finish running under all the circumstances? Or will the loss of connectivity with the workstation cause the database to abort the stored proc?
EDIT: The workstation and the SQL Server are on different boxes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
工作站断电不一定会导致 SP 中止,但很可能会导致事务回滚。
我说“可以”是因为它确实取决于客户端何时失去权力。如果网络连接丢失到像这样的“黑洞”中,服务器将不会立即收到任何断开连接发生的通知;它必须依赖 TCP 最终告诉它连接已死,仅仅是因为对方在 X 时间内没有响应任何内容。
这与显式地“正常”地断开客户端应用程序的连接不同;在这种情况下,客户端会显式关闭连接(如果适用),因此 SQL 会立即知道客户端已消失。
The loss of the workstation's power won't necessarily cause the SP to abort, but it could very well cause the transaction to roll back.
I say "could" because it does depend on exactly when the client loses its power. If a network connection is lost into a 'black hole' like this, the server won't be immediately notified that any disconnect happened at all; it has to rely on TCP eventually telling it that the connection is dead simply because the other side has not responded to anything in X time.
This is different from disconnecting the client application explicitly and 'normally'; in such a case, the client explicitly closes the connection, if applicable, and so SQL will know right away that the client is gone.
由于存储过程在服务器上运行,因此如果 BEGIN/END TRANSACTION 是该存储过程的一部分,则该过程应该运行完成(除非出现任何错误)。当然,客户端永远不会收到任何结果,因为连接丢失了。
Since the stored procedure runs on the server, if the BEGIN/END TRANSACTION are part of that stored procedure the procedure should run to completion (barring any errors). The client will never receive any results, of course, since the connection was lost.
有点相似; SQL Server 和中间的连接丢失transaction
请注意,连接并不总是立即关闭,因此必须预料到意外行为。
Somewhat similar; SQL Server and connection loss in the middle of a transaction
Be aware that connections aren't always shut down immediately, so unexpected behaviour must be anticipated.