The trace file generated by SQL server Profiler allows identifying all queries executed during a session ID on a giver database and the executing time of each query.
For example, to identify a slow query or query making anaman or adgadmin hangs, we can use this tool.
Below different steps allowing generating a trace file in Sql server 2005:
- Launch SQL server 2005 Enterprise management console.
- In Object browser go to Management > Activity Monitor to get the session ID connected on the data base to be monitored.
- Click on Activity Monitor. The below window is displayed.
You can see the name of the database to be monitored in Database column and the session is in Process ID column
- Go to Tools > SQL Server Profiler. Following window is displayed.
- In SQL Server Profiler, go to File > New Trace. A connection dialog box is displayed.
Connect to server hosting CAST database. A trace Properties window is then displayed.
- In General tab, Enter the name of the trace file in Trace name field. The trace file will have a .trc extension.
- Enter in Save to file field the location of folder to save the generated trace file
- Go to Event selection tab. This tab shows different column to be displayed in trace file. You can modify the order of these columns using Organize columns button
- If you need to get all information inside the stored procedure, in the trace properties you have to choose in the "Use the template" field: “TSQL_SPs”
In the "Events Selection" tab, check the following options: RPC:starting, SP:Completed, SP:Starting, SP:StmtStarting
- Click on Column filters button. An Edit filter is displayed as shown below.
- Click on CPU
- Expand Equals
- Enter the session Id
- Click on Run to start the trace file generation. We can see different queries being executed.
- When the process is finish, stop the trace by going to File > Stop Trace.
- Open the trace file by going to File > Open > Trace File.
- You determine the execution time of each query using data in Start time Column
When selecting any line, you can see the whole query script in the bottom .