SQL Server:无法从查询分析器中找到句柄为 10 的准备好的语句
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9830881/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SQL Server: Could not find prepared statement with handle 10 from query analizer
提问by sproketboy
I run the SQL profiler and I want to run some of the queries in the query analyser but I get an error "SQL Server: Could not find prepared statement with handle x".
我运行 SQL 探查器,我想在查询分析器中运行一些查询,但出现错误“SQL Server:找不到带有句柄 x 的准备好的语句”。
Any ideas?
有任何想法吗?
This is the SQL I have copied from the profiler:
这是我从探查器中复制的 SQL:
declare @p1 int
set @p1=10
exec sp_prepare @p1 output,N'@P0 int,@P1 nvarchar(4000),@P2 datetime,@P3 datetime,@P4 datetime,@P5 datetime,@P6 datetime,@P7 datetime',N'SELECT * FROM SCHEDULE WITH (NOLOCK) WHERE RoomNo= @P0 AND STATUS = @P1 AND ( (EndTimeDT <= @P2 AND EndTimeDT > @P3 ) OR (StartTimeDT >= @P4 AND StartTimeDT < @P5 ) OR (StartTimeDT <= @P6 AND EndTimeDT > @P7 ) )',1
select @p1
go
exec sp_execute 10,19,N'A','2012-03-22 16:30:00','2012-03-22 16:00:00','2012-03-22 16:00:00','2012-03-22 16:30:00','2012-03-22 16:00:00','2012-03-22 16:30:00'
go
采纳答案by sproketboy
It seems you need to modify the profiler text if you want to run it in the query analizer.
如果您想在查询分析器中运行它,似乎您需要修改分析器文本。
declare @p1 int
exec sp_prepare @p1 output,N'@P0 int,@P1 nvarchar(4000),@P2 datetime,@P3 datetime,@P4 datetime,@P5 datetime,@P6 datetime,@P7 datetime',N'SELECT * FROM SCHEDULE WITH (NOLOCK) WHERE RoomNo= @P0 AND STATUS = @P1 AND ( (EndTimeDT <= @P2 AND EndTimeDT > @P3 ) OR (StartTimeDT >= @P4 AND StartTimeDT < @P5 ) OR (StartTimeDT <= @P6 AND EndTimeDT > @P7 ) )',1
select @p1
exec sp_execute @p1,19,N'A','2012-03-22 16:30:00','2012-03-22 16:00:00','2012-03-22 16:00:00','2012-03-22 16:30:00','2012-03-22 16:00:00','2012-03-22 16:30:00'
go
回答by Smith
You should use RPC:Starting
queries not RPC:Completed
您应该使用RPC:Starting
查询而不是RPC:Completed
In profiler you would normally see RPC:Starting
and RPC:Completed
. The statement shown in RPC:Staring
is what you need to pick, RPC:Completed
would include output values that were not passed from the client.
在探查器中,您通常会看到RPC:Starting
和RPC:Completed
。中显示的语句RPC:Staring
是您需要选择的,RPC:Completed
将包括未从客户端传递的输出值。
If you use RPC:Completed
you should remove SET set @p1=10
the queries to work
如果您使用,RPC:Completed
您应该删除 SETset @p1=10
查询才能工作
回答by Diego
this is my second answer, I misunderstood the question when I wrote the first one.
这是我的第二个答案,我在写第一个答案时误解了这个问题。
Why are you doing set @p1=10
? You are not supposed to set this variable. try removing it
你为什么要这样做set @p1=10
?您不应该设置此变量。尝试删除它