Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 795787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:32:05+00:00 2026-05-14T22:32:05+00:00

Hope you can help. Is there a way to reliably detect when a stored

  • 0

Hope you can help.

Is there a way to reliably detect when a stored proc is being run on SQL Server without altering the SP itself?

Here’s the requirement. We need to track users running reports from our enterprise data warehouse as the core product we use doesn’t allow for this. Both core product reports and a slew of in-house ones we’ve added all return their data from individual stored procs.

We don’t have a practical way of altering the parts of the product webpages where reports are called from. We also can’t change the stored procs for the core product reports. (It would be trivial to add a logging line to the start/end of each of our inhouse ones).

What I’m trying to find therefore, is whether there’s a way in SQL Server (2005 / 2008) to execute a logging stored proc whenever any other stored procedure runs, without altering those stored procedures themselves.

We have general control over the SQL Server instance itself as it’s local, we just don’t want to change the product stored procs themselves.

Any one have any ideas? Is there a kind of “stored proc executing trigger”? Is there an event model for SQL Server that we can hook custom .Net code into?
(Just to discount it from the start, we want to try and make a change to SQL Server rather than get into capturing the report being run from the products webpages etc)

Thoughts appreciated
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:32:06+00:00Added an answer on May 14, 2026 at 10:32 pm

    You could setup a background trace that is run automatically when SQL Server initializes. Then, in your trace, you could output the trace statement to a table.

    For example, open up SQL Server Profiler. Create the trace you would want, i.e. include SP:Starting and the columns you want. Also choose to save the trace to a table.

    Now, after setting up the script, choose File/Export/Script Trace Definition. This will create a SQL statement that generates the trace.

    Next, create a stored procedure that creates this trace using SQL. Install the proc in the master database and tell SQL Server to run it automatically on startup:

    exec sp_procoption N'sp_MyProc', N'startup', N'true'
    

    Now every time SQL Server restarts, it will configure your trace automatically, and all SP invocations will be logged to a table.

    — EDIT —

    Also note that there are some Dynamic Management Views (DMVs) useful for monitoring stored procedures. Two you might be interested in:

    • sys.dm_exec_procedure_stats
    • sys.dm_exec_query_stats

    For example, sys.dm_exec_procedure_stats will tell you when the proc was last run, how many times it was run, the longest execution time, etc. Note that these views only affect stored procedures currently in the database cache. If the proc is unloaded, so will be the information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I hope there's a SharePoint expert here on SO who can help with this.
Hey guys, sure hope you can help me. I've got around 50 Model-Classes stored
Hey, I hope you can help me. I am trying to find a way
hope someone can help. I appreciate there are a few questions that are similar
Still wrapping my head around SQL and PHP, but hope someone can help with
My question really has three related parts which I hope you can help me
Hey hope someone can help as I am at my wits end with this!?
i have a problem so hope you guys can help! I have a string
I'm fairly new to sql and was hoping that someone can help me with
I hope someone can help me with the following scenario because I'm breaking my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.