Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Is stored procedure running ?

Total Hit ( 3115)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
IF EXISTS (select * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[fnSPisRunning]') AND xtype in (N'FN', N'IF', N'TF'))
   DROP function [dbo].[fnSPisRunning]
GO
CREATE function fnSPisRunning (@objid int)
   returns bit
/*
Description: Tells you IF a stored PROCEDURE IS currently running.

Inputs:
   @objid = the object id OF the stored PROCEDURE you wish to test

Return:
   0 = stored PROCEDURE IS NOT running (or does not exist)
   1 = stored PROCEDURE IS currently running

Example usage:

IF dbo.fnSPisRunning(object_id('LongSP')) = 0
   EXEC LongSP
Else
   PRINT 'LongSP IS already running'
*/



  begin
      DECLARE @return bit
      DECLARE @syscacheobjects TABLE (
          cacheobjtype nvarchar(17) NOT null,
          refcounts int NOT NULL
      )
      INSERT INTO @syscacheobjects
      SELECT cacheobjtype, refcounts
      FROM master.dbo.syscacheobjects WITH (nolock)
      WHERE objid = @objid
      AND    dbid = db_id()
      IF isnull((select refcounts
      FROM @syscacheobjects
      WHERE cacheobjtype = 'Compiled Plan'),0)
      =
      (select count(*)
      FROM @syscacheobjects)
          SET @return = 0 --Not running
      ELSE
          SET @return = 1 --Running
      RETURN @return
end
GO


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.