I have this very simple query in my database in SQL Server 2008 R2:
UPDATE Table1
SET Field1 = 'This value'
WHERE ID = '12345'
I tried to execute this query and I never get successful results. First, it executes for a really long time. One time I executed this query and left it there while I take my lunch. When I came back 2 hours later, it still isn’t finished.
I need to execute this query programatically. I have everything needed to execute it there but the only problem now is that it gives me a “Timeout” error message. I tried increasing my CommandTimeOut but doing so will just hold the program for a longer time. (Since executing the query in SQL Server really takes a long time, please see my scenario earlier)
Can someone please point me to a good solution to avoid this problem? And yes, the table I am accessing has a lot of records like thousands. This has never been a problem before but now it is. 🙁
Thanks in advance 🙂
Sounds like you left open a transaction that locked the row with ID 12345. The command will never finish until you commit or rollback that transaction.
Open the Activity Monitor and see what transaction is blocking your update. Then locate the SSMS window left uncommitted from which you’ve run this transaction and commit or rollback.
For more details see Understanding and resolving SQL Server blocking problems. For general performance troubleshooting methodology see Waits and Queues.