I am trying to run a stored procedure in SQL Server from C#. The stored procedure runs fine in SSMS. It takes 45 seconds to pull these records. However in C# the same call gets a timeout error. What could be the issue here? The XML is a list of Primary Keys from a table in a grid in C#. So it could have 1 line or hundreds of lines. The stored procedure parses it out fine and inserts into a temp table with other data.
SqlConnection connection = new SqlConnection(connectionstring);
ce.Database.Initialize(force: false);
connection.Open();
SqlCommand cmd = new SqlCommand("usp_GetAllAccounts", connection);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@LoanList", DBNull.Value);
cmd.Parameters.AddWithValue("@LoanIdFlagBit",detailModel.activeFlag);
cmd.Parameters.AddWithValue("@DataDtFrom", detailModel.fromDataDt);
cmd.Parameters.AddWithValue("@DataDtTo",detailModel.toDataDt)
cmd.Parameters.AddWithValue("@EffDtFrom",detailModel.fromEffDt)
cmd.Parameters.AddWithValue("@EffDtTo", detailModel.toEffDt)
cmd.Parameters.AddWithValue("@JournalDetailId", detailModel.JournalDetailId)
cmd.Parameters.AddWithValue("@JournalDetailIdList", journalDetailList).DbType = DbType.Xml;
SqlDataReader reader = cmd.ExecuteReader();
My stored procedure code is this:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
@LoanList XML,
@LoanIdFlagBit BIT = 1,
@DataDtFrom SMALLDATETIME = NULL,
@DataDtTo SMALLDATETIME = NULL,
@EffDtFrom SMALLDATETIME = NULL,
@EffDtTo SMALLDATETIME = NULL,
@JournalDetailId INT = 0,
@JournalDetailIdList XML = NULL
AS
SET NOCOUNT ON
Change the CommandTimeout property on your SqlCommand object - The default is 30 seconds;
https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout(v=vs.110).aspx
I believe the default in SSMS is no timeout
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With