High volume site using ADO.NET TransactionScope vs ExecuteCommand on NOLOCK, READ UNCOMMITTED directly?

后端 未结 4 2112
长发绾君心
长发绾君心 2021-02-04 20:33

Just read this interesting article by Omar on his blog Linq to SQL solve Transaction deadlock and Query timeout problem using uncommitted reads and at the end Javed Hasan star

4条回答
  •  鱼传尺愫
    2021-02-04 21:13

    First of all please avoid uncommitted reads, they can cause lots of issues. A much better approach is just to set the database to snapshot isolation. This is what Jeff did.

    Jeff basically said: "bla bla bla, be real, bla bla bla, database theoreticians, bla bla bla, READ UNCOMMITTED can be useful for REAL production apps that don't need data consistency." Jeff is not a DBA, fortunately there are many DBAs out here on SO.

    The problem with Omar's approach is that it can leak connections with "read uncommitted" isolation level in to your connections pool which could wreak havoc in your website. Meaning random statement may be executed in read uncommitted.

    Javed approach would be much better because on dispose MS have the chance to clean stuff up on the connection.

    EDIT If you are having performance issues with Javed's approach you could look at rolling your own transaction manager.

    Some things you probably want to do:

    • Hold a stack of current transactions
    • Confirm you are on the creator thread when a transaction is committed
    • Reset the transaction isolation to its previous state on dispose
    • Rollback on dispose if the transaction was not committed.
    • Support nested rollbacks.

提交回复
热议问题