0

In my ASP.net application I have an SqlDataSource with parameters e. g.:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="..." 
    onselecting="SqlDataSource1_Selecting" ProviderName="System.Data.SqlClient" 
    SelectCommand="SELECT * FROM [SomeTable] WHERE ([SomeTableID] = @SomeTableID)">
    <SelectParameters>
        <asp:ControlParameter ControlID="DropDownList1" Name="SomeTableID" 
            PropertyName="SelectedValue" Type="Int32" />
    </SelectParameters>
</asp:SqlDataSource>

For debugging purposes it would be very helpful to somehow catch the query string which is executed on the database server i. e. the query string with filled in parameter values.

I tried to do this in the SqlDataSource1_Selecting event, but the SqlDataSourceSelectingEventArgs arguments still contain the SelectCommand text as above: SELECT * FROM [SomeTable] WHERE ([SomeTableID] = @SomeTableID).

How can I get the true query string with all @Valiables replaced by the values which are used for the selection?

2
  • Did you try SelectCommand.Parameters? Commented Aug 8, 2013 at 6:28
  • Thanks for your answer. Yes I tried SelectCommand.Parameters and I could get the values one by one there. But if you have a very long query with many parameters this is quite annoying. Commented Aug 8, 2013 at 6:34

1 Answer 1

0

There is no way to view it in code. The SqlCommand class calls sp_execute which separates the query from the parameters. You'll need to use Sql Profiler to see the exact query executed.

You can learn how to use SqlProfiler through this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.