title: How to fix System.Data.SqlClient.SqlException: Timeout expired
body: <p>Hi When I am trying to access my application by URL I am getting the error screen containing the below error. Previously I get it fixed by using dbcc commands in backend..bt now this is not working..</p>
  
  <p>Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. </p>
  
  <p>Exception Details: System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.</p>
  
  <p>Source Error: </p>
  
  <p>An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  </p>
  
  <p>here is my source code for the stored proc I am calling from my .NET application.</p>
  
  <pre><code>      USE [TCO]
  GO
        ALTER PROC [dbo].[SP_TCOV3] (@year INT) AS
  DECLARE @rpt_year INT;
  IF @year &gt; 2011 
  BEGIN
  SET @rpt_year = 2011;
  END
  ELSE
  BEGIN   
  SET @rpt_year = @year;
  END
  DECLARE @From_Date DATETIME='01-01-2012'  -- mm/dd/yyyy
  DECLARE @End_Date DATETIME=(SELECT TOP 1 DATEADD(dd, -DAY(DATEADD(m,1,dbo.ManpowerCost.payment_date)), DATEADD(m,1,dbo.ManpowerCost.payment_date)) as value
  FROM dbo.ManpowerCost order by payment_date desc)  
  
  (
  SELECT
          allApps.[Application Name],          
          '$'+(CAST((CAST(allApps.[BAM Staff Support] AS DECIMAL(10,2))) as varchar(50)))AS [BAM Staff Support],
          '$'+(CAST((CAST(allApps.[BAM Non-Shell Support] AS DECIMAL(10,2))) as varchar(50)))AS [BAM Non-Shell Support] ,
          '$'+(CAST((CAST(allApps.[BSM DBA Support] AS DECIMAL(10,2))) as varchar(50)))AS [BSM DBA Support] ,
          '$'+(CAST((CAST(allApps.[Middleware Support] AS DECIMAL(10,2))) as varchar(50)))  AS [BSM Middleware Support],
          '$'+(CAST((CAST(allApps.[IRM Logical Access] AS DECIMAL(10,2))) as varchar(50)))AS [IRM Logical Access] ,
          '$'+(CAST((CAST(allApps.[Application Licensing and Maintenance] AS DECIMAL(10,2))) as varchar(50))) AS [Application License and Maintenance],
          '$'+(CAST((CAST(allApps.[Middleware Licensing and Maintenance] AS DECIMAL(10,2))) as varchar(50)))as [Middleware License and Maintenance],  
          '$'+(CAST((CAST(allApps.[Database Licensing and T-System DBA Maintenance] AS DECIMAL(10,2))) as varchar(50))) AS [TS DBA Maintenance],
          '$'+(CAST((CAST(allApps.[Hosting and Storage] AS DECIMAL(10,2))) as varchar(50)))AS [Hosting and Storage]  ,
          '$'+(CAST((CAST(allApps.[Telecom Connection Charge] AS DECIMAL(10,2))) as varchar(50))) AS [Telecom Connection Charges],
          '$'+(CAST((CAST(allApps.[Total Application TCO] AS DECIMAL(10,2))) as varchar(50)))AS [Total Application TCO] 
  FROM
          --dbo.FN_TCOV3(@rpt_year)AS allApps 
          dbo.FN_TCOV3_Report(@From_Date,@End_Date)AS allApps 
  
  )ORDER BY allApps.[Application Name]
  </code></pre>
  
  <p>The same proc is working if I do not use start date and end date parameter that I have used above
  and call <strong>dbo.FN_TCOV3(@rpt_year)AS allApps</strong> instead of dbo.FN_TCOV3_Report(@From_Date,@End_Date)AS allApps, the only diff. b/w these two function is one takes only a year as parameter and the other takes 2 parameter namely start and end date.</p>
  
  <p>I need to use both the parameters , Pls assist.</p>