Search This Blog

Most useful developer tools: SQL Server Profiler


posted on Sunday, September 30, 2012

While programming, database actions can be the hardest to debug, since we don't always know which traffic goes from the application to the database.

That's why I would like to introduce another tool in the list of "Most useful developer tools", that makes it possible to trace the database traffic. It will show you all queries sent to the database which could point you to an error in the query or even performance problems if these queries aren't written probably or if they are executed more times than they should be.

So for all your database debugging frustrations: meet SQL Server Profiler!
SQL Server Profiler is part of SQL Server, it's a tool designed to trace database traffic and analyse the results of these traces.It's a debugger tool for SQL Server and therefor, for whatever happens on your database. This tool monitors the database activity in real-time . For example, if you start the profiler and then run a simple select query on your database, you will see your query show up on the profiler.


To open the Profiler, open SQL Server and in the top menu, find the Tools menu. Here you will find a link to the profiler. I believe you can get it separetly as well. All you have to do is, start a new trace and you're ready to go.

You could use the profiler in situations where the query execution happens behind the scenes: think Linq, NHibernate, ... . This tool gives you the opportunity to view and most importantly debug these queries.

When an error in a query occurs, the error thrown in the application is vague and non-specific to what exactly caused the error. So in these situations, you coul view the query in SQL Server Profiler, copy it and run it again. The error in SQL Server will often give you more clarity about what went wrong.

You can find a great step-by-step manual here: http://www.codeproject.com/Articles/21371/SQL-Server-Profiler-Step-by-Step.

Could be useful, right?

No comments:

Post a Comment