PatrickD wrote:
Hi Frans,
I copied the complete statement including the exec sp_executesql and the parameters, so there is no difference.
So I suppose parameter sniffing won't be the issue.
Hmmm. Then I don't know what caused the difference in reads, other than in SSMS it might be it re-used a cached plan or cached sets which had already been evaluated when the ado.net call was executed. One thing which might be causing the difference is that the profiler's data is actually from the server, the SSMS read statistics might be client-side statistics, or did you run it also through profiler?
The thing is, what happens after SqlCommand.Execute...() is called is not up to what we do. We open a connection, call the execute method and that's it. it might be that with the reader, more data is read than when SSMS is returning the complete resultset at once, but I'm not sure what profiling you're looking at: the data read by the profiler from disk or also sent to the client.
Either way, look at the actual execution plan (not the estimated) and see whether indexes were missed or not. The big difference suggests it did a table scan. We can't do much about this as all we do is formulate the query, add the parameters and call execute. What the DB does with it is out of our hands.
Btw, did you have a transaction open when you called the query?
Off-topic: The error when updating my profile:
An error occured. Please try again. If you're using IE6, this might be the reason. In that case, update your browser (e.g. download Firefox).
Not a very informational error message itself, so what can I add to this? BTW, tried on IE and Chrome and same result.
Ah, the default error page. Likely your signature was too long.