2-D 2-D - 4 years ago 91
SQL Question

SQL Server transactions and concurrency

Could someone please explain me this line of code? I was trying to cut it into smaller pieces, but it doesn't ring any bell for me. Thank you.

SqlTransaction transaction = cn.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);

Left side is pretty obvious, then on the right side we call begin transaction method on the connection variable, but the stuff in the () is not quite clear. Thank you.

Answer Source

Your code snippet starts a new transaction with a Read Committed transaction isolation level. Isolation levels are a trait of transactions indicating how isolated the transaction is from the data modifications made by other simultaneous transactions.

See MSDN IsolationLevel Enumeration for more info on the System.Data.IsolationLevel.ReadCommitted isolation level used in your example and for alternatives.

See MSDN Understanding Isolation Levels for more on isolation levels.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download