Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

View CommandText as executed

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hi
I am creating an sql string using Parameters. I set my commandtext of my SqlCommand object to something like this:
Code:
sc.CommandText = "select * from table where value = @parmValue"
sc.Parameter.Add("@parmValue","123")

Now what will get executed on my server will be this

Code:
select * from table where value = '123'

How can I see the sql that .Net will send to the server. I have tried using the Prepare property, then spit out the CommandText, but that does not seem to do the trick.

Any idea's?

Thanks
 
select * from table where value = @parmValue"

that is exactly what gets sent to the server. The value for the parameter is tacked onto the end. Parameratized queries are not just fancy replace functions, they keep the data and the command seperate for a lot of reasons.

You can log in to your SQL Server using enterprise, and use the "Process Info" screen, under "Current Activity", under "Management" It will show you the last query run from each connection.
 
Also, you could start the sql profiler that comes with the SQL server, specify an username & password, set the appropriate filters (like the database name, login name, application name) so that unneeded garbage is not displayed. Then start your application and sit back & relax while the queries are scrolling in front of your eyes :D

What is executed on your server isn't select * from table where value = '123' but is something like:

exec sp_executesql N'select * from table where value = @paramValue', @paramValue int, @paramValue = 123
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top