I'm currently investigating an annoying problem on my website. We're giving away prizes regularly on the website, but to enter the competition people have to login. So the website becomes a lot busy at times. I found that when a lot of people trying to login and register, I get heaps of error about deadlocks on UpdateUser, CheckPassword and GetUser functions then the server gets too busy and other requests start timing out.
When I look into the stored procedures, I found there's ROWLOCK used on 'UpdateUser'. Are those ROWLOCKs causing the deadlock? or only select would result a deadlock?
I was thinking about using NOLOCK for my situation, but after a little research, apparently it's not recommended...
WITH (NOLOCK) is used with SELECT statements when time sensitivity on retrieving data down to the microsecond is not eccential, or selecting a newly added record is down properly.
WITH (ROWLOCK) is used by UPDATE statements to keep the locking of the row at a row level lock and not to escalate it to more than one row or even a table lock.
You should always be using both in you select statements and update statements, as well as you need to properly create indexes, cache repitive data so as not to rapid fire query the database for data that changes little, and look at your login logic to determine if it is not performing unecessary logging of data, and also inspect your SQL error logs for errors that could be slowing access to your web site.