entity framework - SQL Server Express 2008, Joins, and Timeout Expired Error Message -
i have stored procedure quite bit of joins. query though runs pretty fast, around 3 seconds. cant figure out below error poping every once in while. event cache document uses query minute doesnt ran on , over. using entity framework 5, , stored procedure using cte paging. clues or insight?
system.data.sqlclient.sqlexception (0x80131904): timeout expired. timeout period elapsed prior completion of operation or server not responding. ---> system.componentmodel.win32exception (0x80004005): wait operation timed out @ system.data.sqlclient.sqlconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction) @ system.data.sqlclient.sqlinternalconnection.onerror(sqlexception exception, boolean breakconnection, action`1 wrapcloseinaction) @ system.data.sqlclient.tdsparser.throwexceptionandwarning(tdsparserstateobject stateobj, boolean callerhasconnectionlock, boolean asyncclose) @ system.data.sqlclient.tdsparser.tryrun(runbehavior runbehavior, sqlcommand cmdhandler, sqldatareader datastream, bulkcopysimpleresultset bulkcopyhandler, tdsparserstateobject stateobj, boolean& dataready) @ system.data.sqlclient.sqldatareader.tryconsumemetadata() @ system.data.sqlclient.sqldatareader.get_metadata() @ system.data.sqlclient.sqlcommand.finishexecutereader(sqldatareader ds, runbehavior runbehavior, string resetoptionsstring) @ system.data.sqlclient.sqlcommand.runexecutereadertds(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, boolean async, int32 timeout, task& task, boolean asyncwrite) @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method, taskcompletionsource`1 completion, int32 timeout, task& task, boolean asyncwrite) @ system.data.sqlclient.sqlcommand.runexecutereader(commandbehavior cmdbehavior, runbehavior runbehavior, boolean returnstream, string method) @ system.data.sqlclient.sqlcommand.executereader(commandbehavior behavior, string method) @ system.data.sqlclient.sqlcommand.executedbdatareader(commandbehavior behavior) @ system.data.common.dbcommand.executereader() @ system.data.objects.objectcontext.executestorequeryinternal[telement](string commandtext, string entitysetname, mergeoption mergeoption, object[] parameters) @ system.data.objects.objectcontext.executestorequery[telement](string commandtext, object[] parameters) @ system.data.entity.internal.internalcontext.executesqlquery[telement](string sql, object[] parameters) @ system.data.entity.internal.internalcontext.executesqlqueryasienumerable[telement](string sql, object[] parameters) @ system.data.entity.internal.internalcontext.executesqlquery(type elementtype, string sql, object[] parameters) @ system.data.entity.internal.internalsqlnonsetquery.getenumerator() @ system.data.entity.internal.internalsqlquery`1.getenumerator() @ system.collections.generic.list`1..ctor(ienumerable`1 collection) @ system.linq.enumerable.tolist[tsource](ienumerable`1 source) @ tournaments.data.repositories.games.gamesrepository.getgamespaged(igamescriteria criteria)
entity framework method
public pagedresult<gamecomplex> getgamespaged(igamescriteria criteria) { var results = datacontext.database.sqlquery<gamecomplex>("exec [schema].[database] @page, @pagesize, @sortorder, @sortdirection, @eventid, @divisionid, @divisionteamid, @date, @searchtoken, @memberid", new sqlparameter("page", criteria.page), new sqlparameter("pagesize", criteria.pagesize), new sqlparameter("sortorder", getdatavalue(criteria.sortorder)), new sqlparameter("sortdirection", getdatavalue(criteria.sortdirection)), new sqlparameter("eventid", getdatavalue(criteria.eventid)), new sqlparameter("divisionteamid", getdatavalue(criteria.divisionteamid)), new sqlparameter("divisionid", getdatavalue(criteria.divisionid)), new sqlparameter("date", getdatavalue(criteria.date)), new sqlparameter("searchtoken", getdatavalue(criteria.searchtoken)), new sqlparameter("memberid", getdatavalue(criteria.memberid))).tolist(); return new pagedresult<gamecomplex> { page = criteria.page, pagesize = criteria.pagesize, total = results.any(q => q != null) ? results.firstordefault().total : 0, results = results }; }
sql server stored procedure parameter signature
alter procedure [schema].[database] @page int = 1, @pagesize int = 10, @sortorder nvarchar(100) = 'id', @sortdirection varchar(4) = 'asc', @eventid int = null, @divisionid int = null, @divisionteamid int = null, @date datetime = null, @searchtoken nvarchar(100) = null, @memberid int = null
you may need adjust command timeout.
see:
set command timeout in entity framework 4.3
or
how set commandtimeout dbcontext?
edit
command timeout:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx
connection timeout:
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout.aspx
edit:
another possible issue "parameter sniffing".
http://blogs.msdn.com/b/queryoptteam/archive/2006/03/31/565991.aspx
so try 1 of parameter sniffing workarounds:
alter procedure [schema].[database] @page int = 1, @pagesize int = 10, @sortorder nvarchar(100) = 'id', @sortdirection varchar(4) = 'asc', @eventid int = null, @divisionid int = null, @divisionteamid int = null, @date datetime = null, @searchtoken nvarchar(100) = null, @memberid int = null declare @pagecopyof int select @pagecopyof = @page declare @pagesizecopyof int select @pagesizecopyof = @pagesize declare @sortordercopyof nvarchar(100) select @sortordercopyof = @sortorder declare @sortdirectioncopyof varchar(4) select @sortdirectioncopyof = @sortdirection declare @eventidcopyof int select @eventidcopyof = @eventid declare @divisionidcopyof int select @divisionidcopyof = @divisionid declare @divisionteamidcopyof int select @divisionteamidcopyof = @divisionteamid declare @datecopyof datetime select @datecopyof = @date declare @searchtokencopyof nvarchar(100) select @searchtokencopyof = @searchtoken declare @memberidcopyof int select @memberidcopyof = @memberid
and below uses/consumes @xxxxxcopyof variable , not original variable (name).
it's worth try.
Comments
Post a Comment