Adding parameter to SqlCommand hides query from the profiler

  • I am using the SQL profiler to look at queries coming into my sql server. I have noticed that adding actual parameters to my query object in Ado.net causes the query not to show up in the profiler.

    For example, the code below works just fine, but the profiler can't see it. If I comment out the line where I add the parameter, I'll get an error, but the profiler is also able to see the query. What is happening here? Is this a bug? Is there a setting I am missing on the profiler? Currently I have it set to just look for "BatchStarting" events.

    using (var connection = new SqlConnection("Data Source=x2;Initial Catalog=dummy;Integrated Security=True;"))

    {

    connection.Open();

    var command = new SqlCommand( "SELECT COUNT(*) FROM dummyTable WHERE dummyName LIKE @myparam", connection);

    command.Parameters.AddWithValue("myparam", "Fred");

    Console.WriteLine(command.ExecuteScalar());

    }

  • OK, I appear to have fixed it by telling the profiler to watch for RPC:* events. Apparently adding a parameter turns the query into a remote procedure call.

  • ericjorg (6/18/2013)


    OK, I appear to have fixed it by telling the profiler to watch for RPC:* events. Apparently adding a parameter turns the query into a remote procedure call.

    Glad I could help!! 😀

    Best,
    Kevin G. Boles
    SQL Server Consultant
    SQL MVP 2007-2012
    TheSQLGuru on googles mail service

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply