How to set isolation level on SqlCommand/SqlConnection initialized with no transaction

前端 未结 5 1502
忘了有多久
忘了有多久 2020-12-03 10:18

The following method is supposed to peroform a dirty read on an open connection. There are no transactions. Where do I set IsolationLevel?

public string DoDi         


        
5条回答
  •  温柔的废话
    2020-12-03 10:56

    If you don't want to do transactions, you can set it once when you open the connection and it will remain at that setting until you change it. So just do:

    connection.BeginTransaction(IsolationLevel.ReadUncommitted).Commit();
    

    Probably not the best for your specific case, since you are opening the connection, using it, and throwing it away, but I wanted to put this answer in for anyone with a longer-lived connection.

提交回复
热议问题