Active transaction required for write operation

Thread is closed for posting
3 posts, 0 answers
  1. Kwon OhJong
    Kwon OhJong avatar
    5 posts
    Member since:
    Mar 2005

    Posted 16 Nov 2009 Link to this post

    List<UserStudy> = scope.Extent<UserStudy>().Where(c => c.UserId == id).ToList();

    foreach (UserStudy study in userStudies)
        study.PointXml = "1111";


    Server Error in '/Admin' Application.

    Active transaction required for write operation

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: Telerik.OpenAccess.Exceptions.InvalidOperationException: Active transaction required for write operation

    Source Error:

    Line 54:         {
    Line 55:             get { return pointXml; }
    Line 56: set { this.pointXml = value; }Line 57:         }
    Line 58: 
  2. IT-Als
    IT-Als avatar
    381 posts
    Member since:
    Sep 2008

    Posted 17 Nov 2009 Link to this post

    Hi Kwon,

    The exception is correct, since you are trying to change a persistent object (an instance of the UserStudy class) in the foreach loop. OpenAccess doesn't allow you to perform writes to any objects if you not in the scope of a transaction. Be aware that you can perform reads / queries although... That's why you're not getting an exception on your LINQ query.

    So to be able to do what you want, you have to do a scope.Transaction.Begin before you do any changes and a scope.Transaction.Commit after you're done with your changes.

    Note that, it is only during the Commit that changes are written/committed to the database. Until then you're operating only on the objects in scope...


  3. Damyan Bogoev
    Damyan Bogoev avatar
    581 posts

    Posted 17 Nov 2009 Link to this post

    Hello Kwon OhJong,

    Before you can perform any operations on persistent objects, you should start a transaction. This is done with the ITransaction.Begin() method. Any modifications made to an object after beginning the transaction can be stored in the database by calling ITransaction.Commit(). Performing an update operation inside a foreach loop would look like this:

    List<UserStudy> = scope.Extent<UserStudy>().Where(c => c.UserId == id).ToList();
    foreach (UserStudy study in userStudies)
        study.PointXml = "1111";

    You can find additional information about all write operations in this article.
    Hope that helps.

    Damyan Bogoev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top