Base solution for your next web application
Open Closed

Scope for some Read uncommitted values #5987


User avatar
0
mgarcia created

Im trying to make an scope for some Read uncommitted values I need. But I get this error "An ambient transaction has been detected. The ambient transaction needs to be completed before beginning a transaction on this connection." How can I apply some dirty read in web api core 2 project?


3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    Please share your code.

  • User Avatar
    0
    mgarcia created
    User user = null;
    using (var t = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions  
                { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted}))
    {
        {
            user = await UserManager.GetUserByIdAsync(input.UserId);
        }
    }
    
    
  • User Avatar
    0
    ryancyq created
    Support Team

    Hi @mgarcia, can you try to call Complete() in the last line of your scope

    User user = null;
    using (var t = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted}))
    {
        {
            user = await UserManager.GetUserByIdAsync(input.UserId);
            t.Complete();
        }
    }