如何处理多个更新或插入数据库 [英] how to handle multiple update or insert to database

查看:92
本文介绍了如何处理多个更新或插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我是dotnet的新手,并尝试使用vb.net开发基于Internet的mysql-windows applicatin.如果在按钮单击事件中,我正在执行多个更新并将操作插入数据库(例如5个步骤),则需要花费一些时间来完成此操作.如果在此期间,如果我的Internet掉线或发生了某些电源故障,那么如果已经执行了2个步骤,但没有执行其余3个步骤,而前2个步骤需要回滚,该怎么办....

如果我正在使用MysqlTransaction,则对于catch块中的rollBack(),它需要存在连接,但是我没有Internet连接.

有什么建议可以解决这个问题吗??

谢谢

Debasish

Hello,

I''m new in dotnet and trying t develop internet based mysql-windows applicatin using vb.net. If in a button click event, I''m performing multiple updates and insert operation to database(for example 5 steps), then its taking some time to complete this. What happens if during this period, my internet does down or some power failure occurs, then if 2 steps have already executed but rest 3 are not executed and the first 2 need to get rollback....

If I''m using MysqlTransaction, then for rollBack() in the catch block, it needs the connection to be present, but i''ve no internet connection.

Any suggestion how to overcome this problem????

Thanks

Debasish

推荐答案

如果在事务处理期间连接断开,它将自动回滚...

最好的问候
Espen Harlinn
If the connection goes down during a transaction it will be rolled back automagically ...

Best regards
Espen Harlinn


好,我使用了MySqlTransaction并在try块事务中使用.Commit()
并且我省略了catch块中的transaction.RollBack()...至于回滚它需要有效的连接,但我的连接已断开...

我得到了撤消第一条语句的结果,因为直到transaction.commit()发生,所有插入或更新都发生在某个临时空间中,所以直到transaction.commit()才影响真正的数据库.
ok,, I''ve used MySqlTransaction and in the try block transaction.Commit()
and I''ve omitted the transaction.RollBack() inside the catch block... as for rolling back it requires a valid connection but my connection is broken...

I got my result of undoing the 1st statement as till transaction.commit() happens, all the insert or update happens in some temporary space, so is not affecting the real database till transaction.commit() .


这篇关于如何处理多个更新或插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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