1

I have a scenario where users may update a list item at the same time and this causes a Save Conflict error.

I could catch the exception and reload the list item as suggested in http://adrianhenke.wordpress.com/2010/08/20/sharepoint-error-save-conflict-your-changes-conflict-with-those-made-concurrently-by-another-user/ but I'm concerned that reloading the list item may not be foul-proof.

Would applying a lock help?

    private static readonly object oLock = new object();

    lock(oLock)
    {
        using(SPSite site = new SPSite("http://site.com")
        {
             using(SPWeb web = site.OpenWeb("/subsite"))
             {
                   SPList list = new web.Lists["ListName"];
                   SPListItem item = list.GetItemById(idNo);
                   item.Update();
             }
        }
    }
1

Applying lock would help you and also you should add some sleep after updating the listitem. But this does not mean that error will never occur. So after updating your code you should test it properly with simultaneously updates.

2
  • Thanks for the help, Aanchal! I would still need to add sleep? Are there other scenarios I haven't seen in which the error can still occur? I thought that acquiring the lock before opening the list and list item can help me from preventing the error.
    – Celbester
    Jun 18 '14 at 6:05
  • 1
    Yes, it would. But i have read that sharepoint also aquire some temporary lock while updating, that's why i suggest to add sleep. Also you should add try catch block and in catch block try to reload the item and apply update.
    – Aanchal
    Jun 18 '14 at 6:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.