Automating the Infrastructure

Focusing on scripts, MOM, SMS, WMI, and any other technologies design to assist operations staff in performing their entire job function from the comfort of their own desk.

Blank Description in SQL Server 2005 Block Analysis script

I found that block analysis script for SQL 2005 was generating an appropriate alert, but the description is blank.  That description is pretty important because it identifies the process blocking and being blocked.

After some investigation, I found that there is a problem on the line of the script building the description - specifically where we include the time that the black has been occuring.  This is pulled from the waittime field of the sysprocesses table.  It turns out that this field was an Int in SQL 2000 but changed to a BigInt in SQL 2005.  The script uses a CInt to covert this value to an Integer which results in an overflow.  Since we run into an error building the description, it's left blank in the alert.

Fortunately, this is trivial fix - just a matter of swapping out that CInt.  I found that to get a correct calculation, I had to convert to a Double prior to performing the division required to convert the value from milliseconds into minutes. 

The offending line is 2240 by my count.  Just modify as follows:

Original line

""" has been blocked for " & CStr(CInt(rsBlockedSPIDS("waittime").Value / 1000 / 60)) & _

 

Changed Line

""" has been blocked for " & CStr(CInt(CDbl(rsBlockedSPIDS("waittime").Value) / 1000 / 60)) & _

 

Published Saturday, April 08, 2006 10:46 PM by Brian Wren
Filed under:

Comments

 

Poornima.ashwin said:

Hi, I have been working on MOM 2005 for sometime now. I have a question on how we could send a consolidated email on occurances of blocks on the SQL server. As of now MOM seems to be sending 1 email for each blocked SPID and because there are huge number of blocks at one time on the SQL server it seems to send out multiple emails. I checked on Alert suppression which was not much of a help. I checked if we could use a Consolidation rule to send emails but unable to give the event criteria to the Consolidation rule. Can one of you help me on this..its really annoying getting multiple emails for an instance of blocking on the servers

July 31, 2007 8:12 AM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker