Thursday, December 26, 2013

"select * from table" and "select top 14260 from table" get nothing but select top 14259 get result successful


When the table data is locked, is this bug of Sqlserver or bug of my java program? And how can I sove this problem?



It's not a bug in SQL Server. It may be an issue in your Java program, but it does not have to be.


To troubleshoot this, first start the query that hangs. Then run sp_who2. Keep an eye of the Blk column. If there is a number in this column, this spid is blocking the spid on this line. Find the blocking spid in the output, and see what application the spid comes from. Maybe it is coming from SQL Server Management Studio, because you failed to commit or rollback transaction when you were playing around. It the blocker is from your Java application, you probably have a problem to take care of. Beware that the blocker may be blocked in its turn; but you can easily see this in the output from sp_who2.


And no, you should not use NOLOCK. That's only good to troubleshoot the issue, so that you can verify that it is due to locking.





Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

No comments:

Post a Comment