I have a site collection that has ~600 sub-sites. Each sub-site has a sub-site, as well, making a total of ~1200 sites.
I am iterating through each site and updating (resetting) a list. This is done once a day during non-working hours(100 am). 99% of the time there is no problem, but every now in then during the run, I will get the following exception:
Microsoft.SharePoint.SPException: Save Conflict.
Your changes conflict with those made concurrently by another user. If you want your changes to be applied, click Back in your Web browser, refresh the page, and resubmit your changes. ---> System.Runtime.InteropServices.COMException: Save Conflict.
I am sure there are no users on at the time of the conflict and there are no other applications that would be touching those sites.
I read one post that said I should re-get the list object before I do a List.Update()
. I tried this, and it definitely cut down on the frequency of the save conflict, but I still get it now and then (about once a week). Below is my code:
SPList list;
list = web.Lists["Milestones"];
for (int i = list.ItemCount - 1; i >= 0; --i)
{
Console.WriteLine("Deleting {0}", list.Items[i].Title);
list.Items[i].Delete();
}
foreach (var milestone in project.Milestones)
{
Console.WriteLine("Adding {0}", milestone.Description);
SPListItem item = list.Items.Add();
item["LineNumber"] = milestone.LineNumber.ToString();
item["Title"] = milestone.Description;
item["DueDate"] = milestone.ExpectedDate.Value;
item.Update();
}
try //Trying to stop save conflict
{
list = web.Lists["Milestones"]; //trying to stop save conflicts.
//Found answer that said that if updating in a loop you
//should re-get the list object
//Not in a loop, but thought it worth trying.
list.Update(); //exception happens here sometimes
}
catch (Microsoft.SharePoint.SPException sPex)
{
SendEmailToEadt(string.Format(
"Error in {0} project. {1} On List.Update {2}{3}", project.Number,
Environment.NewLine, Environment.NewLine, sPex.ToString()));
}
foreach (SPWeb childWeb in web.Webs)
{
UpdateMilestones(childWeb, project);
}
My question is: Why does re-getting the list seem to reduce the save conflicts? And more importantly, since I am only doing one list.update() per site/list, how is there a save conflict at all?
list.Update()
? Is there allways items in each list?