Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server: Could not find prepared statement with handle 10 from query analizer

Tags:

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".

Any ideas?

This is the SQL I have copied from the profiler:

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 
like image 730
sproketboy Avatar asked Mar 22 '12 21:03

sproketboy


2 Answers

You should use RPC:Starting queries not 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.

If you use RPC:Completed you should remove SET set @p1=10 the queries to work

like image 118
Smith Avatar answered Sep 17 '22 19:09

Smith


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

like image 22
Diego Avatar answered Sep 16 '22 19:09

Diego