Sql Solutions
  • Home
  • Sql

Thursday, 7 July 2016

Kill Sleeping Threads in SQL to Remove DeadLock Condition

 Unknown     22:11     No comments   


 Use This Process to Kill sleeping Threads in sql


CREATE proc [dbo].[KillProcess]               
as             
begin    
 declare @msrno1 varchar(10) ,@spid varchar(110)='',@count int =0, 
 @mysql varchar(100)='' 
  
      
   DECLARE  C21 CURSOR FOR select spid from sysprocesses where status = 'sleeping' and   cmd='AWAITING COMMAND' order by   spid 
   OPEN C21     
   FETCH FROM C21 INTO @msrno1      
   WHILE @@FETCH_STATUS = 0 BEGIN 
   set @count=0  
   set @mysql=''    
      select @count= count(1) from sysprocesses where spid=@msrno1 and  status = 'sleeping'   and         cmd='AWAITING COMMAND' 
      if @count>0 
      begin 
      set @mysql= 'kill '+ cast(@msrno1 as varchar(10))  
      exec( @mysql) 
      end 
        
   FETCH FROM C21 INTO @msrno1      
   END     
   CLOSE C21     
   DEALLOCATE C21     
     
    
         
          
  Select 'Done'          
          
            
end
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

About Me

Unknown
View my complete profile

Popular Posts

  • How to use cursor in SQL Server
    Please Use  this in your procedures and functions    DECLARE  C21 CURSOR FOR  <Query to find Value on basis of ...>    OPEN C21  ...
  • Reduce log file size in sql server
    Dear all these are the query to reduce  size of log file in sql  Query 1 ALTER DATABASE databasename SET RECOVERY SIMP...
  • Shrink Database File
    By Using This query we can reduce database file Firstly we should get File Name by Using This with TblSpace as (     select       ...
  • Right Use of Transaction Using TRY catch
    This is right use of SQL transaction Using TRY Catch for  Avoid DeadLock Condition BEGIN TRANSACTION TransRavi BEGIN TRY <Do Y...
  • Calculate Age in SQL Server
    Please Pass your date of birth in "DD/MM/YYYY" format and get age ..... Create a Procedure... create Proc dbo.CalculateAge...
  • Remove Deadloack Condition in sql server
    Use this query to drop all kind of Transaction Deadlock in Sql Server ALTER DATABASE <DataBase Name> SET SINGLE_USER WITH ROLLBACK ...
  • Find text in whole database procedures
    For Finding particular text in stored procedures  please put your text on the place of <Text> and get result... SELECT  c.name...
  • Generate Script of a Table in Sql server (Using Query)
    Step 1. Please pass Your table Name in this Stored Procedure and get script Create Proc dbo.Ravi_Script_Table (@tablename varchar(50)) ...
  • Get Script of Stored Procedures and views
    Please Write this qurey and get
  • Kill Sleeping Threads in SQL to Remove DeadLock Condition
     Use This Process to Kill sleeping Threads in sql CREATE proc [dbo].[KillProcess]                as              begin      declare @ms...

Copyright © Sql Solutions | Powered by Blogger
Design by Ravi Budania