how to find recently executed queries in a specific database by a specific application?

Chaitanya Kiran 801 Reputation points
2022-01-12T09:35:12.777+00:00

how to find recently executed queries in a specific database by a specific application?

SQL Server Other
{count} votes

2 answers

Sort by: Most helpful
  1. Olaf Helper 47,436 Reputation points
    2022-01-12T14:32:14.303+00:00

    SQL Server do have some execution statiscs, see sys.dm_exec_query_stats (Transact-SQL)
    But not on the level you are looking for, for this you have to implement your own audit/logging.

    0 comments No comments

  2. AmeliaGu-MSFT 14,006 Reputation points Microsoft External Staff
    2022-01-13T03:02:06.15+00:00

    Hi ChaitanyaKiran-2787,
    Agree with others. You can select three events RPC:Completed, SP:StmtCompleted and SQL:BatchCompleted in the SQL Server Profiler, and make sure column ApplicationName, DatabaseName and textData is selected.

    164576-image.png

    And then click on the "Column Filters..." button to filter the specific database and application name.

    164466-image.png

    Or you can use Extended event, which is similar with SQL Server profiler. In the new session wizard, select rpc_completed,sql_batch_complete and sql_batch_starting events, and make sure client_app_name, database_name and sql_text is clicked in “capture Global Fields” page, then filter the database and application name in the “Set Session Event Filters” page.

    Please refer to Use SQL Server Profiler to trace database calls from third party applications and Quickstart: Extended events in SQL Server which might be helpful.

    Best Regards,
    Amelia


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.