SQL事务问题 [英] Sql Transaction Problem

查看:111
本文介绍了SQL事务问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个要实现SQLTransaction的项目.在form_Load事件中,我创建并应用它.然后在SAVE_Click中,我要根据条件进行Commit()或RollBack()交易.

但是直到我关闭提交或回滚,我的其他数据库命令才执行,并且请求获取超时.

请帮我.我没有问题.

I am developing a project where I want to implement SQLTransaction. In form_Load Event I create and apply it. and In the SAVE_Click I want to Commit() or to RollBack() the transaction depending on a condition.

But until I close commit or rollback my other Database Commands are not executing and Request get Timeout.

Please help me. I am not getting the problem.

推荐答案

我会重新考虑设计,您只需要在事务内部执行插入/更新/删除操作,因此可以在内部创建事务SAVE_Click方法.

最好的问候
Espen Harlinn
I would rethink the design, you only need to execute the inserts/updates/deletes inside the transaction - so create your transaction inside the SAVE_Click method.

Best regards
Espen Harlinn


这是一个非常糟糕的设计.

事务应尽可能短,因为它们占用了RDBM服务器上的资源.

您应该绝对不从表单加载开始,然后单击按钮进行提交/回滚,这可能介于10秒到10分钟之间.
This is a very bad design.

Transactions should be as short as possible as they take up resources on the RDBM server.

You should absolutely not start on form load and commit/rollback on a button click which could be anything between 10 secs to 10 minutes in between.


同时同意好答案.一个非常重要的经验法则是:事务中永远不要进行用户对话!没有问题,没有通知,只是纯逻辑和SQL语句的执行.如果您必须向用户提出要求,请在交易之前进行.如果遇到问题,请回滚,然后通知用户.

如果您需要知道用户进行修改时情况没有改变,请使用开放式锁定.悲观锁定不适合较长时间.
Agree with both good answers. A very important rule-of-thumb is: Never have user conversations inside a transaction! No questions, no notifications, just pure logic and executions of SQL statements. If you have to ask something from the user, do it before the transaction. If you encounter problems, rollback and then inform the user.

If you need to know that the situation has been unchanged while the user makes modifications, use optimistic locking. Pessimistic locking just isn''t suitable for longer periods of time.


这篇关于SQL事务问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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