Selected code is stored from code, runs fine with SSMS
I have a stored procedure that takes about 10 seconds to run when called from SSMS and succeeds. The procedure takes a parameter int
as a parameter.
When calling the same stored procedure from code:
using (var connection = new SqlConnection(ConnectionStringName))
{
using (var cmd = new SqlCommand("ProcedureName", connection))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@itemId", itemId));
cmd.CommandTimeout = 150;
connection.Open();
cmd.ExecuteNonQuery();
}
}
The error I am getting is the following:
System.Data.SqlClient.SqlException (0x80131904): Timeout expired.
The timeout period elapsed prior to completion of the operation or the server is not responding. --->
System.ComponentModel.Win32Exception (0x80004005): The wait operation timed out
The passed parameter is valid and executes correctly when the stored procedure is called from SSMS with the same parameter value.
+3
source to share