Query with actual values of parameters

O

Oleg Ogurok

Hi all,

I'm defining a query as "INSERT INTO Table (Col1, Col2) VALUES (@Val1,
@Val2)"
Then I'm creating a SqlCommand and adding the parameters @Var1 and @Var2 and
their corresponding values using sqlCommand.Parameters.Add(....) I
understand the framework then substitutes the formal parameters for their
actual values and passes the resulting query into the database for
execution.

Is there a way to get that actual query string being passed into the
database? Some of my queries fail, and I have no idea how to troubleshoot
them.

Thanks,

-Oleg.
 
J

Jon Skeet [C# MVP]

Oleg Ogurok said:
I'm defining a query as "INSERT INTO Table (Col1, Col2) VALUES (@Val1,
@Val2)"
Then I'm creating a SqlCommand and adding the parameters @Var1 and @Var2 and
their corresponding values using sqlCommand.Parameters.Add(....) I
understand the framework then substitutes the formal parameters for their
actual values and passes the resulting query into the database for
execution.

Is there a way to get that actual query string being passed into the
database? Some of my queries fail, and I have no idea how to troubleshoot
them.

Depending on the database protocol, there may never *be* an actual SQL
query being constructed. However, you could always turn on profiling on
the database itself and see if that helps.
 
L

Lloyd Sheen

You will see that your T-SQL is sent with parameters. Going way back to
db-lib this was the case. The T-SQL and parameters are sent as the T-SQL
string followed by the definition of all parameters and then the values for
those parameters. The only thing missing is the declare statement for each
parameter.

Lloyd Sheen
 
J

Jon Skeet [C# MVP]

Lloyd Sheen said:
You will see that your T-SQL is sent with parameters. Going way back to
db-lib this was the case. The T-SQL and parameters are sent as the T-SQL
string followed by the definition of all parameters and then the values for
those parameters. The only thing missing is the declare statement for each
parameter.

Interesting. This strikes me as a bit of a waste of resources: after
all, if the client has already got the data in a native form, why
shouldn't it transmit it in that form and avoid text formatting and
parsing? That goes double if the statement is prepared - with a
prepared statement, I wouldn't have thought *any* text parsing should
be necessary on the server side, just receiving bunches of values at a
time.

Admittedly I basically know nothing about database internals, but I
would have thought that would be a more efficient way of doing
things...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top