Raw SQL sent to SQL Server from .NET on stored procedure call

Posted by Jeff Meatball Yang on Stack Overflow See other posts from Stack Overflow or by Jeff Meatball Yang
Published on 2010-04-20T22:03:20Z Indexed on 2010/04/20 22:13 UTC
Read the original article Hit count: 257

Filed under:
|

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'");

}

© Stack Overflow or respective owner

Related posts about sql-server

Related posts about .NET