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
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With