Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Database Command Timeouts: Performance Differences between .NET and Management Studio

RSS
Modified on Fri, Jan 06, 2012, 5:35 PM by Administrator Categorized as ASP·NET Web Forms, SQL Server, ·Net Framework

Overview

Why are there performance differences when a SQL statement is called from .NET app versus when the same call is made in Management Studio?

Resolution 1: Recompilation

The root of the problem is a stale execution plan for the stored procedure being called. The first time the stored procedure is called after it’s compiled, SQL Server builds an execution plan for it based on the parameter values submitted. The solution was to recompile the stored procedure, then execute it within Management Studio with the parameters that causes the timeout when called from .NET. This causes SQL Server to build a new execution plan based on parameter values that returned data.


Resolution 2: Variable Substitution

Old Code

create procedure dbo.MyProcedure (
    @regionID int
    ) as 

. . .
where RegionID = @regionID

New Code

create procedure dbo.MyProcedure (
    @regionID int
    ) as 

declare @l_RegionID int

set @l_RegionID = @regionID

. . .
where RegionID = @l_RegionID

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.