October 6, 2010 at 4:55 am
I have a stored procedure, which is inserting rows into a particular table, I know that it runs once a day, but I cannot find the SQL Agent job that is running this SP.
How can I find out what is executing the SP?
October 6, 2010 at 4:58 am
If it is sqlagent have a look at the sysJobSteps table in msdb
October 6, 2010 at 5:19 am
Thanks for the reply Dave.
I have checked dbo.sysjobsteps where command contains the SP name, but I'm not getting any results back.
So if it is not an SQL Agent job, where else can I look?
Thanks
October 6, 2010 at 5:32 am
Is it being called by another SP ?
take a look at the INFORMATION_SCHEMA.ROUTINES view.
October 6, 2010 at 5:42 am
barry can you edit the procedure? I would add a simple but detailed auditstatement to dump the snippet below into a table in master or call sp_send_dbmail, so you could track down where and when this is occurring;
I'd try to gather this info from within the proc:
SELECT
getdate() as EventDate,
DB_NAME() As dbname,
HOST_NAME() As hostname,
APP_NAME() as applicationname,
OBJECT_NAME(@@PROCID) as procedurename,
USER_ID() as userid,
USER_NAME() as unsername,
SUSER_ID() as suserid,
SUSER_SNAME() as susername,
IS_SRVROLEMEMBER ('sysadmin') AS [Is_ServerAdmin_Sysadmin],
IS_MEMBER('db_owner') AS [Is_DB_owner],
IS_MEMBER('db_ddladmin') AS [Is_DDL_Admin],
IS_MEMBER('db_datareader') AS [Is_DB_Datareader],
ORIGINAL_LOGIN() AS [ORIGINAL_LOGIN],
client_net_address as ipaddress
from sys.dm_exec_connections
where session_id = @@spid
Lowell
October 6, 2010 at 6:03 am
What about setting up a server side trace to monitor for that query? You can capture who is calling it, when, from where, pretty much everything you need.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 6, 2010 at 6:48 am
possibly a windows scheduled task? Running a SQLCMD statement?
is it possible that the SP is triggered from something else?
October 6, 2010 at 7:57 am
barry.smallman (10/6/2010)
I have a stored procedure, which is inserting rows into a particular table, I know that it runs once a day, but I cannot find the SQL Agent job that is running this SP.How can I find out what is executing the SP?
Hi
Check with depends(sp_depends), this sp might be inner sp for some other sp.If the primary sp executes the inner sp(yours) will also executes
Thanks
Parthi
Thanks
Parthi
October 6, 2010 at 9:02 am
parthi-1705 (10/6/2010)
barry.smallman (10/6/2010)
I have a stored procedure, which is inserting rows into a particular table, I know that it runs once a day, but I cannot find the SQL Agent job that is running this SP.How can I find out what is executing the SP?
Hi
Check with depends(sp_depends), this sp might be inner sp for some other sp.If the primary sp executes the inner sp(yours) will also executes
Thanks
Parthi
That's an older approach to checking for dependencies and doesn't always work that well. Using sys.dm_sql_referencing_entities works better. Not perfectly, but better.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
October 6, 2010 at 9:44 am
Or do
select top 10 * from syscomments
where text like '%spNameHere%'
to see if it's called from any other SPs.
October 6, 2010 at 12:04 pm
I'd recommend sys.sql_modules - something like
SELECT OBJECT_NAME(object_id) FROM sys.sql_modules WHERE charindex('spNameHere',definition)>0;
The text column in syscomments has a limit of nvarchar(4000) and SPs with definitions greater than that size will be trimmed to that limit...the definition column in sys.sql_modules is nvarchar(max)
October 6, 2010 at 1:32 pm
October 7, 2010 at 2:37 am
Hi All,
I have made a massive blunder here.
I have posted this query in the wrong forum.
My instance is a SQL Server 2000 instance NOT 2005.
Sorry.
With this in mind, which of the suggested methods still hold true?
October 7, 2010 at 3:15 am
Which of the steps did you try? The ones that fail will be SQL 2005 specific 🙂
Bad jokes aside - on SQL 2000 the recommendations that involve sys.dm_exec_connections, sys.sql_modules, sys.dm_sql_referencing_entities will not work as these objects are present in 2005.
Did you try Grant's suggestion of using a server side trace to capture how the SP is getting executed?
October 7, 2010 at 3:39 am
Hi,
Yes, I tried amending the SP to query the sys.dm_exec_connections DMV as suggested in the reply by Lowell!!
When the stored procedure failed to run this morning, I started investigating why it couldn't find the DMV, only to discover that this is a SQL Server 2000 instance!
(I have an excuse - I've only been here a week, so I'm still learning what instances exist)
I shall have to look into using the server side trace approach, but that will take some investigation, as I have never set one up before.
Viewing 15 posts - 1 through 15 (of 19 total)
You must be logged in to reply to this topic. Login to reply