I am trying to find out why a stored procedure call takes several seconds in the SQL Server express query window, but when I start the stored procedure call in code, the TIMES OUT request. We are using SQL Server 2008. I know that it’s hard to say exactly what happens without seeing the stored procedure. I just hope this is a known issue. Any recommendations are greatly appreciated.
An SQL query that calls "STORED_PROCEDURE_X" and runs after 2 seconds in the SQL Server Express Query window:
EXEC STORED_PROCEDURE_X '07/01/2010', '07/31/2010', 0, '', 'true','', 'Top 20'
Code that calls "STORED_PROCEDURE_X" and TIMES OUT:
SqlConnection connSQL = null;
SqlCommand sqlCmd = null;
SqlDataAdapter sqlDataAdpater = null;
DataTable returnData = null;
try
{
returnData = new DataTable();
connSQL = new SqlConnection(sqlConnection);
sqlCmd = new SqlCommand("STORED_PROC_X", connSQL);
if (connSQL.State == ConnectionState.Closed)
{
connSQL.Open();
}
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.CommandTimeout = 600;
sqlCmd.Parameters.Add("@StartDate", SqlDbType.NVarChar).Value = "07/01/2010";
sqlCmd.Parameters.Add("@EndDate", SqlDbType.NVarChar).Value = "07/31/2010";
sqlCmd.Parameters.Add("@AuditType", SqlDbType.Int).Value = "0";
sqlCmd.Parameters.Add("@SortBy", SqlDbType.NVarChar).Value = "";
sqlCmd.Parameters.Add("@IsClaimDepartment", SqlDbType.NVarChar).Value = "true";
sqlCmd.Parameters.Add("@IdsList", SqlDbType.NVarChar).Value = "";
sqlCmd.Parameters.Add("@ReportType", SqlDbType.NVarChar).Value = "Top 20";
sqlDataAdpater = new SqlDataAdapter(sqlCmd);
sqlDataAdpater.Fill(returnData);
if (connSQL.State == ConnectionState.Open)
{
connSQL.Close();
}
return returnData;
}
catch (Exception ex)
{
LogErrorMessages("ExecuteStoredProcedure", ex.Message);
throw ex;
}
Ruled out:
System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
source
share