views:

430

answers:

1

Hi All,

I have been doing some performance analysis on an application I am working on. The application is web-based (asp.net) using an old version of NHibernate (1.0) on MSSQL Server (2005).

Running profiler against the application seems to show something a little odd, in that we seem to be querying objects twice, once as a direct query and once wrapped in sp_executesql. for example:


SELECT col1, col2 FROM TABLE
exec sp_executesql N'SELECT col1, col2 FROM TABLE'

Looking at the stats within profiler I can see they are distinct events (the select is recorded as event 45 - SP:StmtCompleted whilst the call to sp_executesql is recorded as event 10 - RPC:Completed).

I have not worked with NHibernate too much before this, but I cannot imagine this is normal behavior. Am I either mis-reading the profile trace (in which case how should I interpret the above), or is there a good reason for this?

If the above is as bad as I think, is there a way to switch this behavior off?

Thanks

+3  A: 

your queries are not run twice. It's just that those 2 events are fired for the same statement.

Mladen Prajdic
ok - so for my understanding, why is one wrapped in sp_executesql, and the second not?
Chris
and why does running an sp_executesql statement manually not reproduce the same behavior?
Chris
i'm not familiar with NHibernate that much, but i'd guess that it happens because of it's command settings. It would seems really strange that they would fire twice.
Mladen Prajdic