Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

We got code, running on page load. That code asks certain SPList for its items by CamlQuery, which gets only items with specific (current) user in one field (field A) and with some value in other field (field B). Combination of those two field makes items unique.

So when there is no such item, we create new one.
If there is such item, we only update it.

So we dont want to have duplicate items with same values in fields A and B. And code which I described, works pretty well.
With one little exception - when user have more than one home page set on our SharePoint in his browser, every loading homepage executes this code at the same time. That means GetItems with caml query returns no item in both cases, so both requests creates same new item.

Questions are: Can we avoid this? How? Are there any logical errors in how we manipulate with items?

share|improve this question
add comment

1 Answer 1

up vote 1 down vote accepted

As long as you don't have a SharePoint farm with multiple WFE servers, you should be able to solve this problem by enclosing the critical code section in a lock statement.

Related questions from StackOverflow:

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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