MS SQL 2005

We need to Monitor the SQL Blocks and currently we don’t have any tool in place,

Is it possible to monitor the SQL blocks like which user ,SPID ,query blocked via script?

The alert supposed to trigger via E-mail with valid information,

Step by step method much appreciated
Raja PAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
what about starting with this support note?
Mark WillsTopic AdvisorCommented:
Along similar lines, there is a good dialogue and explanation about blocked processes :

The typical source to identify blocks is via the DMV sys.dm_os_waiting_tasks and a good description / guide.

If you were to simply do :
select * from sys.dm_os_waiting_tasks

Open in new window

You'll get an idea of what is available, but read the article so you are not watching for legit wait states and only look for those problem waits.
Raja PAuthor Commented:
I need to monitor the SQL Blocks not to identify SQL blocks

My requirement is ---  if there is any block for 30 Min then it need to trigger the alert via Email to notify the DBA for further investigation.

I have already tried   but it generating the Output file in specified location, this will useful  for further investigation  once we got the Email notification for SQL Blocks.

Looking for Live monitor for SQL Blocks
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Ryan McCauleyEnterprise Analytics ManagerCommented:
I wrote about 75% of an application one time that would execute an "sp_who2" on a server every couple of seconds and display the results as a "blocked process tree" of sorts, displaying processes that were blocked and by whom. It had the option to alert you in the system tray, but it could easily be enhanced to send emails when certain events occurred. The core functionality works fine, but the app crashes occasionally and the polish isn't there, but it gets the job done.

I've attached a screenshot - is this what you're looking for? I haven't done any development on it in about three years, but if it is, I'll open a Codeplex project and post the source (it's in VB.NET). I originally had plans to finish and sell it, but never got around to it and I'm more than happy to open-source it at this point.Screenshot of SQL Contention Monitor
Raja PAuthor Commented:

Looks Good ,Can you share the source code if it open soure

Thank you so much
Ryan McCauleyEnterprise Analytics ManagerCommented:
Sure, I'll throw it up on Codeplex so others have access as well. there may even be some desire to improve it. I know Redgate sells a product that's similar now (they didn't when I began development a few years ago - alas), but I think it's $200/server.

I'll wander through the source code tonight to see if I need to scrub it at all, and then I'll post it to Codeplex and post an update here.
Anthony PerkinsCommented:
I know Redgate sells a product that's similar now (they didn't when I began development a
few years ago - alas), but I think it's $200/server.

Are you referring to SQL Monitor ?
Mark WillsTopic AdvisorCommented:
Looking forward to seeing ryanmccauley's codeplex...

And yes, Redgate does have a product - but it is a bit more than a couple of hundred (try several hundred) :

But there are others I have heard of like SQL Block Monitor (has alerts) for less than a hundred on single server :  and Idera has similar (but wider range of monitoring) :

It would be possible to set up your own monitor, but would be involved and require a fairly high understanding of the internals. Done right it can be made to work. Done wrong and then you might find significant performance impacts, and you dont want the lock manager to be resident and continually running (might want to double check the advanced sp_configure option 'blocked process threshold').

That's why the third party options suddenly come into their own - they watch and alert in such a way that they minimise impacts.

It also depends a little on how responsive you need the alerts to be... If there is a block for thirty minutes then that is a lifetime in SQL terms. So if it is to identify and subsequently analyse the root cause (and fix) then it is a little bit different to being alerted of a currently running process so you can intervene - and in that case it is more likely to be minutes to raise an alarm.

If writing your own code and applications, then there are other tools like ApexSQL that can help with the development process and help you tune and optimise to avoid potential problems.

Do you have budget for third party tools, or is this something that you really want to resolve / develop yourself ?
Ryan McCauleyEnterprise Analytics ManagerCommented:
After playing around with the code a bit, I'm realizing it's more rough than I remember, but it still gets the (basic) job done. It was also my first shot at mainstream multi-threading, so it's a bit dirty in that regard and I'd probably do things a bit differently if I had it to design over again. I'm open to suggestions in this area for small enhancements that might stabilize things.

I've created the project and uploaded both the source code and the compiled EXE to Codeplex:

Please let me know how it works (or doesn't) for your needs. A few notes:

It only supports integrated auth at this point. The methods and storage is set up to handle SQL auth as well, but the interface doesn't have any way for you to store credentials
When you first launch it, you'll see LOCALHOST. The third button down on the left is "Settings" and will let you add more servers to monitor.
For some reason, the panels don't display correctly at first and aren't lined up. Clicking on another panel, and then back on the initial panel again will fix this. I'd alos love to know why this happens
The project, since it was only intended to be a tool I used, is remarkably devoid of comments. If you have any questions about why I'm doing something they way I am, please post to the discussion board on the Codeplex project and I'll answer it promptly! Also, feel free to suggest features or enhancements on that site as well - while this isn't a primary priority of mine, I'll add what enhancements I can, especially as it helps stabilize the application and add basic functionality.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.