Can I select data during a transaction?

I use a transaction to make sure that the data is read into the database correctly. However, I may need to select some data (from another page) during the transaction. Can this be done? I know very poorly when it comes to databases.

I am using LinqToSQL and SQL Server 2005 (dev) / 2008 (prod).

+3
source share
3 answers

Yes, you can still select data from the database during the transaction.

, (, , ), . ( SQL Server , , - ).

, , .

#, .

TransactionOptions option = new TransactionOptions();        
options.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;        
using (TransactionScope sc = new TransactionScope(TransactionScopeOption.Required, options)
{
    // Code within transaction
}

, , ( , NOLOCK), , , . , READUNCOMMITTED . , () .

, SERIALIZABLE, , , .

+1

, TransactionScope , . , TransactionScope TransactionOptions IsolationLevel.ReadUncommitted:

TransactionScopeOptions = new TransactionScopeOptions();
options.IsolationLevel = IsolationLevel.ReadUncommitted;
using(var scope = new TransactionScope(
    TransactionScopeOption.RequiresNew, 
    options
) {
    // read the database
}

LINQ to SQL DataContext:

// db is DataContext
db.Transaction = 
    db.Connection.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted);

, System.Transactions.IsolationLevel System.Data.IsolationLevel. , .

0

. . Read Committed Snapshot ON , . , .

, , tempdb, . .

Exict, , TransactionScope Serializable, , ReadCommited. , , , ReadCommited.

0

Source: https://habr.com/ru/post/1725909/


All Articles