Trace (e.g., OutputDebugString / Trace.writeline) from a SQL Server stored procedure

I was looking for some time to track the SQL stored procedure on SQL Server. I'm talking about tracing in "DebugView", like the OutputDebugString () (or C # Trace.WriteLine ()) function.

Does anyone know how to do this, or if possible?

Thank!: -)

+3
source share
1 answer

How do you execute these stored procedures? If SSMS reports print faster and easier, if you can use custom SQL Profiler Events from your application .

You can disable and disable logging by changing the connection string.

IF APP_NAME() LIKE '%Debug%'
BEGIN
    DECLARE @msg NVARCHAR(128), @user_data varbinary(8000)
    SELECT  @msg = N'A message', @user_data = cast('some data' as varbinary(8000))
    EXEC sp_trace_generateevent 82, @msg, @user_data
END
+1
source

Source: https://habr.com/ru/post/1785536/


All Articles