Click here to Skip to main content
15,445,641 members
Articles / Web Development / ASP.NET
Posted 18 Oct 2011


10 bookmarked

.NET Code or SQL – Where’s the Performance Problem?

18 Oct 2011CPOL2 min read
Identifying an application’s performance bottlenecks is all about understanding how the application is spending its time. Only with the most complete understanding of how an application is operating is it possible to understand what it is doing wrong, as this article describes.

This article is in the Product Showcase section for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers.

Many modern applications rely on a database back-end, and for those building for the Microsoft stack, SQL Server is the data layer of choice. While in many cases the performance of an application will be CPU-bound, often bottlenecks turn out to lie with the application’s database interaction. This makes understanding the code’s SQL activity vital for getting a hold on its performance.

One approach used in the past has been to run the SQL Server Profiler at the same time as a separate performance profiler. This lets you understand code performance and look at SQL activity separately, but understanding how the two are related can be difficult and time-consuming. Sometimes slow or repeated queries are OK and don’t need optimizing, but it all depends on the context in which whose queries were run.

Profiling Cubed in ANTS Performance Profiler builds SQL profiling into the same performance profiler used for analyzing .NET code performance. Results can be compared side by side, with SQL and code performance data automatically matched up against each other on the interactive timeline.

Why would you want SQL data in your code profiler?

Let’s look at an example. The Beer House is an ASP.NET website using SQL Server as the data layer. After attaching ANTS Performance Profiler, detailed performance data is collected. Using the interactive timeline, we can select any period to analyze code performance, drilling down to view line-level timing data for any method. While this approach is immensely useful for finding CPU-related slowdowns, it is less helpful when the database is the bottleneck. In Figure 1, the btnVote_Click() method is taking a long time to run but, after looking at the timing in the source code window, this doesn’t seem to be because of the performance of the code itself.


Figure 1. Code performance data, including line-level timing

After selecting btnVote_Click(), and switching to the SQL Server data tab, we can see all database activity on the local server for that same timespan. We can examine which queries were run and get timing information and the number of rows returned. This helps identify occasions where queries are being run unnecessarily, often to re-fetch data which might better have been cached, or where the same query is run multiple times in quick succession by mistake.


Figure 2. Detailed SQL activity for the selected timespan

To see SQL profiling in action, watch this short video.

SQL profiling is part of Profiling Cubed in ANTS Performance Profiler, which brings together SQL, File I/O, and .NET code profiling into the same tool for the most complete understanding of your application’s performance.

Learn more about Profiling Cubed, or download you free 14-day trial.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Red Gate Software Ltd.
United Kingdom United Kingdom
Redgate makes ingeniously simple software used by 804,745 IT professionals and counting, and is the leading Microsoft SQL Server tools vendor. Our philosophy is to design highly usable, reliable tools which elegantly solve the problems developers and DBAs face every day, and help them adopt database DevOps. As a result, more than 100,000 companies use products in the Redgate SQL Toolbelt, including 91% of those in the Fortune 100.
This is a Organisation

1 members

Comments and Discussions

QuestionAppealing but no thanks PinPopular
Pascal Ganaye18-Oct-11 8:21
MemberPascal Ganaye18-Oct-11 8:21 
AnswerRe: Appealing but no thanks Pin
cdkisa18-Oct-11 14:16
Membercdkisa18-Oct-11 14:16 
GeneralRe: Appealing but no thanks Pin
Lutosław20-Dec-11 2:58
MemberLutosław20-Dec-11 2:58 
AnswerRe: Appealing but no thanks Pin
John Brett18-Oct-11 21:26
MemberJohn Brett18-Oct-11 21:26 
GeneralRe: Appealing but no thanks Pin
Pascal Ganaye18-Oct-11 22:00
MemberPascal Ganaye18-Oct-11 22:00 
GeneralRe: Appealing but no thanks Pin
BrianBissell25-Oct-11 9:02
MemberBrianBissell25-Oct-11 9:02 
GeneralRe: Appealing but no thanks Pin
radioman.lt25-Nov-11 2:38
Memberradioman.lt25-Nov-11 2:38 
AnswerRe: Appealing but no thanks Pin
GaryWoodfine 15-Dec-11 22:24
professionalGaryWoodfine 15-Dec-11 22:24 
GeneralRe: Appealing but no thanks Pin
Pascal Ganaye16-Dec-11 3:15
MemberPascal Ganaye16-Dec-11 3:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.