Is there a way to see the exact SQL being generated from a
parameterized query? I am using this technique but am getting some
strange SQL errors during execution and I would like to see the final
SQL that is being generated.
Lasse Vågsæther Karlsen - 26 May 2008 17:41 GMT
> Is there a way to see the exact SQL being generated from a
> parameterized query? I am using this technique but am getting some
> strange SQL errors during execution and I would like to see the final
> SQL that is being generated.
A parameterized query doesn't generate any other sql, the query is sent
as-is to the database engine along with the parameter values, and the
database engine puts them all together.
In short, unless you're using a database that actually rewrites the sql
with the parameter values verbatim, you won't get what you're asking for.

Signature
Lasse Vågsæther Karlsen
mailto:lasse@vkarlsen.no
http://presentationmode.blogspot.com/
PGP KeyID: 0xBCDEA2E3
Marc Gravell - 27 May 2008 08:03 GMT
Just additional - most database enginers come with a trace/profiler
facility that can be used to see the final SQL statements. This is handy
when the code is auto-generated (LINQ-to-entities for example), but I
agree with the last reply: in this case it sounds like it will be sent
verbatim.
Marc
Alberto Poblacion - 27 May 2008 09:39 GMT
> Is there a way to see the exact SQL being generated from a
> parameterized query? I am using this technique but am getting some
> strange SQL errors during execution and I would like to see the final
> SQL that is being generated.
If you are using Microsoft SQL Server, it includes a tool "SQL Server
Profiler". If you run it, it will let you capture all the SQL that the
server is receiving from the client. You may find it useful to examine the
calls that the client is sending to the server. As others replied before,
you will find out that the parameterized query is sent "as is", along with
the values of the parameters.