I have a stored procedure in SQL Server 2008R2 that does several updates/merges ... if the procedure is called roughly simultaneously by two processes it has a relatively high chance of deadlocking.
I'd like to solve this problem by making my stored procedure not re-entrant. That is I would like all calls to the stored procedure to be serialized. Put a final way, I'd like any call to the stored procedure to block indefinitely until any other running instance of the procedure is complete (and then any blocked calls are allowed to run one at a time).
My calling code is C#... i know how to serialize code on a synchronization object in C# and was hoping to conceptually accomplish the same thing in SQL Server 2008 R2.
What is the best way to do this?