Should I commit or rollback a read transaction?

后端 未结 12 1166
臣服心动
臣服心动 2020-12-02 10:42

I have a read query that I execute within a transaction so that I can specify the isolation level. Once the query is complete, what should I do?

  • Commit the tr
12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-02 11:39

    If you put the SQL into a stored procedure and add this above the query:

    set transaction isolation level read uncommitted
    

    then you don't have to jump through any hoops in the C# code. Setting the transaction isolation level in a stored procedure does not cause the setting to apply to all future uses of that connection (which is something you have to worry about with other settings since the connections are pooled). At the end of the stored procedure it just goes back to whatever the connection was initialized with.

提交回复
热议问题