Search code examples
sqlasp.netado.netparameterized-query

Check raw DB query after parameter binding in ASP.NET


I am making a query with ASP.NET with SqlConnection and SqlCommand. I am adding parameters to the query with the AddWithValue method, to avoid SQL injection.

I want to check the resultant query after the parameters have been included, for debug purposes. If I have "WHERE name = @myName", I want to see the query after @myName has been replaced. Is this possible?

Thank you.


Solution

  • Not really, because .NET never sends the complete query. The query is assembled by the database when it receives the SQL string and the parameter values.

    The most you can do is log the SQL string, and log the values of the parameters you passed to it. From that you should still be able to easily infer what query was actually executed.