entity framework - SQL Server sp_executesql timeout -


the following query (without details) ends timeout. columns have nvarchar type. not this. query works without sp_executesql.

exec sp_executesql n'declare @exp nvarchar(max) = ''%'' + @name + ''%''  select u.id [local_db]..users u     join [linked_server].[remote_db].dbo.players p on p.playerid = u.playerid     join [linked_server].[remote_db].dbo.playerstats ps on ps.playerid = u.playerid @exp null or u.nickname @exp or u.name @exp or p.nickname @exp order ps.wins desc offset @skip rows fetch next @take rows only',n'@skip int,@take int,@name nvarchar(8)',@skip=0,@take=24,@name=n'foo' 

i've found interesting details. if remove or p.nickname @exp, works. same happens, when remove or u.nickname @exp or u.name @exp. it's thought.


update

next query works fine!

exec sp_executesql n' declare @skip int = 0, @take int = 24, @name nvarchar(8) = n''foo'' declare @exp nvarchar(max) = ''%'' + @name + ''%''  select u.id [local_db]..users u     join [linked_server].[remote_db].dbo.players p on p.playerid = u.playerid     join [linked_server].[remote_db].dbo.playerstats ps on ps.playerid = u.playerid @exp null or u.nickname @exp or u.name @exp or p.nickname @exp order ps.wins desc offset @skip rows fetch next @take rows only' 

queries sp_executesql , without have different execution plans (why???). in case of sp_executesql profiler suggested me create index on users(playerid) included columns (id, name, nickname). , works charm! if encounter problem, try profile query.


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -