• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 516
  • Last Modified:

Db Blocking/Locking

I need a script that can send an email to Ohemaa@yahoo.com when
there is

1. a lock on the database Customer  
2. The head of the blocking chain
3. the query that the spid that is blocking is running....

  • 2
  • 2
1 Solution
CREATE Proc sp_getlocks

I'm sure this will answer your questions...

alittle more you.
 http://msdn2.microsoft.com/en-us/library/ms187749.aspx as well as doing a google search for more information on lock types, etc.
ohemaaAuthor Commented:
I have seen all these links.  just not sure how to put it all in a nice simple script..
It is what is called shared intent lock on a table.

Try creating the following procedure (I put it in the master database). It will give more informative lock info:

CREATE Proc sp_getlocks
Create Table #locks
      (spid       int,
      dbid       int,
      objid       int,
      indid       int,
      type       char(5),
      Resource nvarchar(255),
      Mode      nvarchar(255),
      Status      nvarchar(255))

Insert #Locks Exec Master.dbo.sp_lock

select  P.loginame, P.spid, d.name as 'Database', S.name as 'Object' ,P.cmd,
      l.type as 'LockSize', l.mode as 'lockMode', l.status, P.blocked, P.waittime
      From #Locks L
      Join sysobjects S
            on L.ObjID = S.ID
      Join Master.dbo.sysprocesses P
            on L.spid = P.spid
      Join master.dbo.sysdatabases D
            on l.dbid = d.dbid
      Order by p.loginame,P.spid, P.dbid, s.name

ohemaaAuthor Commented:
Does not alert me.   I am looking for some form of alert so that we ca resolve the issue before users start calling
1. a lock occurs on  database  
2. The head of the blocking chain or who is causing the locking/blocking
3. the query that the spid that is blocking is running....

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now