Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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?

share|improve this question
    
Did you try SelectCommand.Parameters? –  Tim Aug 8 '13 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. –  Rob Aug 8 '13 at 6:34

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.