Reputation: 67898
Consider a block of code like this:
using (SqlConnection c = new SqlConnection("{connection string}"))
{
c.Open();
using (SqlCommand cmd = new SqlCommand("INSERT INTO Table (Field1, Field2) VALUES (@Field1, @Field2)", c))
{
cmd.Parameters.AddWithValue("@Field1", "some value");
cmd.Parameters.AddWithValue("@Field2", 10);
cmd.ExecuteNonQuery();
}
}
I would like to be able to see the actual statement sent to the server, but the kicker is I don't have access to SQL Server Profiler via our Network/SQL administrators. Is there any way I can get at the actual statement submitted to the server?
Upvotes: 2
Views: 981
Reputation: 1062965
There are a range of tools that do exactly this. If you are in asp.net, you may find MiniProfiler a good start (you can use it on other platforms, but the UI tooling is stronger on asp.net). The main change involved here would be to move from SqlCommand etc to use c.CreateCommand
, since it works by wrapping the connection (decorator pattern) - while it is still a DbConnection, the outermost object is not a SqlConnecion any more. I have to say, though - in this particular example you already know the exact command sent to the server. It is useful for finding the surprises, though. If that doesn't suit, "Hibernating Rhinos" offer a range of profiling tools, and many Orpheus general-purpose profiling tools will include ado.net tools; the main reason I mention MiniProfiler is that is is free, readily available, and very low impact (it is what we wrote to profile stackoverflow.com - and we leave it "on" 24x7)
Upvotes: 2