0

Assuming i have a stored procedure (example as follows)

CREATE OR ALTER PROCEDURE test
AS
BEGIN
    SELECT * FROM sys.tables;
    WAITFOR DELAY '01:00'
    SELECT * FROM sys.tables
END
GO;

and I have a c# invocation of a SQLCommand that runs a stored procedure as follows

using (var connection = new SqlConnection(connectionString)){
        connection.Open();
        using(var command = new SqlCommand("test", connection)){
            command.CommandType = CommandType.StoredProcedure;
            command.ExecuteNonQuery();
        }
    }

Is there a way for me to get at the underlying sql statement currently being executed within the stored procedure?

What I would like to get is the ability to log, "SELECT * FROM sys.tables", "WAITFOR DELAY '01:00'", etc.

badazzhindu
  • 913
  • 7
  • 21
  • 1
    No, that is not possible. All that is being sent to sql server is what you see there. If you want the content of the stored procedure there are commands you can issue to Sql Server to retrieve that but you need access rights to do so. – Igor Mar 26 '20 at 14:59
  • 1
    Is is not using code, but I find really useful SQL Server Profiler, I use it to monitor wtf is done inside stored procedures, when I have performance problems, things like that – Cleptus Mar 26 '20 at 15:11

0 Answers0