In using SqlCommand.CommandText MSDN tells us it returns the name of the SP when calling an SP. For debugging purposes I would like to be able to extract the SQL as it is run in the DB along with params. This way I can run EXEC and slap on the SQL for debugging in the database or displaying debugging info to other programmers.
Can it be done?
Sure it can, but only if you’re not using named parameters.
If you use named SQL parameters, there is no SQL that can do exactly what the call does from the debugger.