The transaction operation cannot be performed because there are pending requests working on this transaction

user662285 picture user662285 · Apr 13, 2015 · Viewed 7.9k times · Source

I am getting error as :

An error was reported while committing a database transaction but it could not be determined whether the transaction succeeded or failed on the database server. See the inner exception and http://go.microsoft.com/fwlink/?LinkId=313468 for more information.

The transaction operation cannot be performed because there are pending requests working on this transaction.

i am trying to insert data to DB using Entity Frameowrk using MapStoredProcedure approach.

My Code :

this.MapToStoredProcedures(e => e.Insert(v => v.HasName("uspInsertUser").Result(rs => rs.UserId, "UserId")));

 public ActionResult Add(User userDetails)
        {
            try
            {
                _unitOfWorkAsync.BeginTransaction();

                _userService.Insert(userDetails);
                _unitOfWorkAsync.SaveChangesAsync();

                _unitOfWorkAsync.Commit(); // This line gives error
                ModelState.Clear();    

                return View("Add");
            }
            catch (Exception ex)
            {
                _unitOfWorkAsync.Rollback();
                throw ex;
            }

The most weird thing about this is if i keep a breakpoint and debug the code while insert it insert successfully.

However, when i insert without any breakpoint enabled it gives me above error. Any help is appreciated.

Answer