Jim Rogers

Lives in Baton Rouge, LA, with two dogs, one cat, and one lovely wife. I'm a lead developer for GCR & Associates.

Katrin and Jim

Month List

Running NHibernate queries in management studio

by Jim Mar 17, 2011 5:33 PM
If you watch your NHibernate-generated queries go by in SQL Profiler, you’ll see a whole lot of SQL that looks like this:
declare @p1 int
set @p1=11
exec sp_prepexec @p1 output,N'@p0 varchar(8000),@p1 ...
SELECT TOP (@p1) this_.ProjectId as ProjectId78_0_, ...
',@p0='jimrogers',@p1=10,@p2='jimrogers',@p4=10
select @p1
But if you try to paste that into SQL Management Studio and run it, you get this error:
Msg 8179, Level 16, State 2, Procedure sp_prepexec, Line 1
Could not find prepared statement with handle 11.
Getting the query to run is simple enough – just comment out or delete the second line:
declare @p1 int
--set @p1=11
exec sp_prepexec @p1 output,N'@p0 varchar(8000),@p1 ...
SELECT TOP (@p1) this_.ProjectId as ProjectId78_0_, ...
',@p0='jimrogers',@p1=10,@p2='jimrogers',@p4=10
select @p1

Comments (1) -

6/27/2011 10:45:48 PM #

happytony

May i know why need to delete the second line. which exist in the profiler.
can share the idea? and email to me. Thanks

happytony United States

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading