Parameterized Query

  • Thread starter Thread starter xlar54
  • Start date Start date
X

xlar54

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.
 
xlar54 said:
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.
 
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
 
xlar54 said:
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.
 
Back
Top