04 February,2013 by Jack Vamvas
When an application uses ADO,OLE DB or ODBC to interact with SQL Server , the preparation and execution model uses sp_prepare and sp_execute to prepare statements. If you attempt to execute just the sp_execute part in Query Analyzer - the message Msg 8179 Could not find prepared statement with handle appears
The sp_prepare portion parses and compiles the statement execution plan. The sp_execute portion executes the Execution Plan.
A typical example extracted from a SQL Server Profiler Trace is :
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 BOOKINGS WITH (NOLOCK) WHERE TableNo= @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','2013-03-21 16:30:00','2013-03-21 16:00:00','2014-03-20 16:00:00','2014-03-20 16:30:00','2012-03-22 16:00:00','2012-03-22 16:30:00' go
If you extract the sp_execute portion , and attempt to run in Query Analyzer , an error message appears Msg 8179 Could not find prepared statement with handle. Avoid this message by including the related sp_prepare portion of the trace
Troubleshooting the SQL Profiler trace Attention - SQL Server DBA
SQL Server execution plan as text - SQL Server DBA
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |