Are long-living transactions acceptable?

后端 未结 5 712
孤街浪徒
孤街浪徒 2020-12-11 04:41

I am thinking about using transactions in 2-tier WPF (or windows forms) applications in following way:

We can begin new transaction when we open new form for editing

5条回答
  •  情话喂你
    2020-12-11 05:22

    Here is a few problem that you might encounter if you go this way

    • connection reset/close/timeout (if user goes to the bathroom)
    • database configuration (database are mostly pre-configured for many short transactions, not long ones. E.g. the undo log that keeps track of what has been done during the tx may need to be tuned)
    • lock issues, even maybe deadlocks (the longer the transactions are, bigger the chances are the same lock is acquired twice possibly in conflicting order)

    This is a discouraged practice. Use optimistic locking instead. Read data when necessary, keep a copy in memory. When dialog is closed, attempt to synchronize the changes with the database. If data have been modified in the database in between, the action is aborted. The probability that it fails will depend on the numer of users, etc. But this is frequently acceptable in practice.

提交回复
热议问题