I've been looking for a while for a way to trace from SQL stored procedure on SQL Server. I am talking about tracing to "DebugView", just like the function OutputDebugString() (or C#'s Trace.WriteLine()).
Does anyone know how to do that, or if it is 开发者_StackOverflow社区even possible?
Thanks! :-)
How are you executing these stored procedures? If from SSMS print statements are quickest and easiest if from your application you can use custom SQL Profiler Events.
You could toggle logging off and off by altering 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
精彩评论