IDb事务回滚超时
我正在处理一个有趣的情况,我在单个事务中执行许多数据库更新。 如果这些更新因任何原因失败,事务将回滚。
IDbTransaction transaction
try {
transaction = connection.BeginTransaction();
// do lots of updates (where at least one fails)
transaction.Commit();
} catch {
transaction.Rollback(); // results in a timeout exception
} finally {
connection.Dispose();
}
我相信上面的代码通常被认为是在事务中执行数据库更新的标准模板。
我面临的问题是,虽然 transaction.Rollback() 被发送到 SQL Server,但它在客户端上也超时了。
无论如何,是否可以区分发出回滚命令的超时和该命令执行完成的超时?
提前致谢, 本
I am dealing with an interesting situation where I perform many database updates in a single transaction. If these updates fail for any reason, the transaction is rolled-back.
IDbTransaction transaction
try {
transaction = connection.BeginTransaction();
// do lots of updates (where at least one fails)
transaction.Commit();
} catch {
transaction.Rollback(); // results in a timeout exception
} finally {
connection.Dispose();
}
I believe the above code is generally considered the standard template for performing database updates within a transaction.
The issue I am facing is that whilst transaction.Rollback() is being issued to SQL Server, it is also timing out on the client.
Is there anyway of distinguishing between a timeout to issue the rollback command and a timeout on that command executing to completion?
Thanks in advance,
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该指定特定的捕获,即查看引发的不同异常。 如果在处理 sql 命令时出现错误,则应抛出 SqlException,以便捕获不同的异常以在项目中进行区分。
此外,您还可以捕获并编程
异常 - 尝试提交事务时发生错误。
InvalidOperationException - 事务已提交或回滚。
-或者-
连接已断开。
安德鲁
You should specify particular catches i.e. Look at the different exceptions that are thrown. If there is an error whilst processing the sql command then a SqlException should be thrown so catch the different exceptions to differentiate in your project.
Further more you could also catch and program for
Exception - An error occurred while trying to commit the transaction.
InvalidOperationException - The transaction has already been committed or rolled back.
-or-
The connection is broken.
Andrew