Raw SQL sent to SQL Server from .NET on stored procedure call
- by Jeff Meatball Yang
Is there a way to get the raw text that is sent to SQL Server, as seen in SQL Profiler, from the ADO.NET call?
using(SqlConnection conn = new SqlConnection(connString)) {
SqlCommand cmd = conn.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "GetSomeData";
cmd.Parameters.Add("@id").Value = someId;
cmd.Parameters.Add("@someOtherParam").Value = "hello";
conn.Open();
SqlDataReader dr = cmd.ExecuteReader();
// this sends up the call: exec GetSomeData @id=24, @someOtherParam='hello'
// how can I capture that and write it to debug?
Debug.Write("exec GetSomeData @id=24, @someOtherParam='hello'");
}