MS SQL Profiler – Limiting trace information by database name

Okay, this is going to be a really short post about MS SQL profiler (yay, my first post about MS SQL :D ). In case you are not aware of the sql profiler (which I am sure most of the developers are aware of), it’s a tool used to view the queries issued by various applications to a database server. “SQL Server Profiler” is normally present in the following location All Programs\Microsoft SQL Server 2008\Performance Tools\SQL Server Profiler. Once you launch this executable, you can use the File menu to start a new trace session (File -> New Trace). Then you will have to enter the database server name and the login credentials. Once you click on “Connect”, you will get the “Trace Properties” dialog. When you hit on “Run”, all the queries issued by various applications to this database server can be seen. Now let me get to the most interesting part.

At times, in a database server that has a number of databases accessed by a number of applications, it may be really difficult keep track all the traced events. Of course, you can use Ctrl + F, but this is much more interesting as you pretty much get a limited amount of data to look at. The profiler has an option to limit the trace to a specific database. This post is going to discuss with images as to how this filter can be applied so as to limit the amount of trace information.

First, when you choose File -> New Trace, you get the trace window as shown below. Notice the 2nd tab “Events Selection”. Select that tab.

Initial trace properties window

In this tab, look for the “Show all columns” checkbox and check it. Then click on the “Column Filters” button.

Initial trace properties window

Now in the “Edit Filter” dialog displayed look for the “DatabaseName” and select it. Then in the right pane, in the tree displayed, expand “Like“. You now get a text box where you can enter the database name. Now click the OK button and now you are all set. You can also enter multiple database names here. You get a new text box whenever you enter a database name.

Initial trace properties window

Now, you get back to the “Trace Properties” window. When you hit on “Run”, you only see the traces for the database you selected!

If you knew this already, this could be a refresher of sorts! But I came to know of this only today :( , but still happy to know this!!!

Hope this post was helpful!

Share