Tonto Tonto - 1 year ago 115
ASP.NET (C#) Question

Timeout expired on a C# method

I have an already running stored procedure on mssql that was running ok. 3 days ago, running the same procedure in code started giving me Timeout expired. Have tried checking if there are any running process on the underlying table but there appears to be none. Checked for deadlock situations and there's none as well. Can anyone suggest what to do next to get this resolved?

Here's the code

public DataSet rptPaymentsByDateOptions(DateTime dateFrom, DateTime dateTo, string level, string sessionID, string degreeID, string programID, string jrnalSrce)
DataSet ds = new DataSet();
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmdSem = db.GetStoredProcCommand("[iSchool].[rptCurrentSem]");
DbCommand cmd = db.GetStoredProcCommand("[iFinance].[rptPaymentsByDateOptions]");
db.AddInParameter(cmd, "DateFrom", DbType.Date, dateFrom);
db.AddInParameter(cmd, "DateTo", DbType.Date, dateTo);
db.AddInParameter(cmd, "Level", DbType.String, level);
db.AddInParameter(cmd, "SessionID", DbType.String, sessionID);
db.AddInParameter(cmd, "DegreeID", DbType.String, degreeID);
db.AddInParameter(cmd, "ProgramID", DbType.String, programID);
db.AddInParameter(cmd, "JrnalSrce", DbType.String, jrnalSrce);
db.LoadDataSet(cmdSem, ds, "rptCurrentSem");
db.LoadDataSet(cmd, ds, "rptPaymentsByDateOptions"); //Timeout error here
return ds;

If i execute the rptPaymentsDateOptions stored procedure in management studio, it runs successfully.

Answer Source

You can increase the timeout

DbCommand.CommandTimeout Property

You could also review your tables and data to see if any additional indexes might speed up the query.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download