Trace an application module in SQL Server

Tracing an application module in SQL Server can be achieved using SQL Server Profiler, Extended Events, or SQL Server Audit. Here’s a detailed guide on how to use these tools to trace a specific application module:

Using SQL Server Profiler

SQL Server Profiler is a graphical tool that allows you to monitor events in the SQL Server database engine. It is useful for tracing and debugging SQL queries executed by an application module.

Step 1: Launch SQL Server Profiler

  1. Open SQL Server Management Studio (SSMS).
  2. Go to Tools -> SQL Server Profiler.

Step 2: Create a New Trace

  1. In SQL Server Profiler, click on File -> New Trace….
  2. Connect to the SQL Server instance.

Step 3: Configure Trace Properties

  1. Trace name: Enter a name for your trace.
  2. Use the template: Select a template such as Standard (default).

Step 4: Filter Events for the Application Module

  1. Go to the Events Selection tab.
  2. Click on Column Filters….
  3. In the ApplicationName filter, specify the name of the application module you want to trace. This name usually matches the application name specified in the connection string.

Step 5: Start the Trace

  1. Click Run to start the trace.
  2. SQL Server Profiler will capture and display the events related to the specified application module.

Step 6: Analyze and Save the Trace

  1. Monitor the captured events in real-time.
  2. Save the trace to a file or a table for further analysis by going to File -> Save As.

Using SQL Server Extended Events

Extended Events is a lightweight performance monitoring system that helps collect detailed information about SQL Server events.

Step 1: Create an Extended Event Session

  1. Open SQL Server Management Studio (SSMS).
  2. Expand Management, right-click Extended Events, and select New Session….

Step 2: Configure Session Properties

  1. Session name: Enter a name for your session.
  2. Template: You can use a template or start with a blank session.

Step 3: Add Events to the Session

  1. Go to the Events page.
  2. Click Add Event….
  3. Select events related to the application module, such as sqlserver.sql_batch_completed and sqlserver.rpc_completed.
  4. Add these events to the session.

Step 4: Filter Events

  1. On the Events page, select the event and click on the Configure button.
  2. Go to the Filter (Predicate) tab.
  3. Add a filter for sqlserver.client_app_name and set it to the application module name.

Step 5: Configure Data Storage

  1. Go to the Data Storage page.
  2. Configure how the event data should be stored (e.g., ring buffer or event file).

Step 6: Start the Extended Event Session

  1. Click OK to create the session.
  2. Right-click the new session and select Start Session.

Step 7: Monitor and Analyze Events

  1. Right-click the session and select Watch Live Data to monitor events in real-time.
  2. Analyze the captured events to trace the application module.

Using SQL Server Audit

SQL Server Audit can be used to track and log database events for security and compliance purposes.

Step 1: Create an Audit

  1. Open SQL Server Management Studio (SSMS).
  2. Expand Security, right-click Audits, and select New Audit….
  3. Audit name: Enter a name for your audit.
  4. Audit destination: Choose where to save the audit logs (e.g., file, security log, or application log).

Step 2: Create an Audit Specification

  1. Expand Security, right-click Server Audit Specifications or Database Audit Specifications, and select New Audit Specification….
  2. Audit Specification Name: Enter a name for your audit specification.
  3. Audit: Select the audit you created earlier.

Step 3: Add Audit Actions

  1. Add actions to capture events, such as SCHEMA_OBJECT_ACCESS_GROUP to log access to schema objects.
  2. Optionally, add a filter to the audit specification to capture events related to the specific application module. For example, filter by the ApplicationName.

Step 4: Enable the Audit and Audit Specification

  1. Right-click the audit and select Enable.
  2. Right-click the audit specification and select Enable.

Step 5: Review Audit Logs

  1. View the audit logs by querying the audit file or using SQL Server Management Studio.

Conclusion

Tracing an application module in SQL Server involves using tools like SQL Server Profiler, Extended Events, or SQL Server Audit. These tools allow you to capture and analyze SQL queries and other database activities generated by a specific application module, helping you monitor performance, debug issues, and ensure security compliance. By following the steps outlined in this guide, you can effectively trace and analyze the activities of your application module in SQL Server.

This entry was posted in MSSQLServer on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply