Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Adding parameter to SqlCommand hides query from the profiler Expand / Collapse
Author
Message
Posted Tuesday, June 18, 2013 5:25 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, June 4, 2014 4:35 PM
Points: 13, Visits: 32
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());
}

Post #1464915
Posted Tuesday, June 18, 2013 5:43 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, June 4, 2014 4:35 PM
Points: 13, Visits: 32
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.
Post #1464918
Posted Tuesday, June 18, 2013 8:48 PM


SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 2:23 PM
Points: 4,350, Visits: 6,160
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 at GMail
Post #1464937
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse