This is a migrated thread and some comments may be shown as answers.
Active transaction required for write operation
2 Answers 42 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kwon OhJong
Top achievements
Rank 2
Kwon OhJong asked on 17 Nov 2009, 01:40 AM
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 Answers, 1 is accepted

Sort by
0
IT-Als
Top achievements
Rank 1
answered on 17 Nov 2009, 10:55 AM
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...

Regards

Henrik
0
Damyan Bogoev
Telerik team
answered on 17 Nov 2009, 12:59 PM
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();
 
scope.Transaction.Begin();
 
foreach (UserStudy study in userStudies)
{
    study.PointXml = "1111";
}
 
scope.Transaction.Commit();

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

Regards,
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.
Tags
General Discussions
Asked by
Kwon OhJong
Top achievements
Rank 2
Answers by
IT-Als
Top achievements
Rank 1
Damyan Bogoev
Telerik team
Share this question
or