I am would like to display progress feedback for user while stored procedure is running (multiple setps). All sql code is in transaction so I am using a service broker to get a real time updates. Could you suggest what is wrong with code below as I am not getting any messages in my queue?
Is there a better way of doing it?
--queue
create queue myQueue
--service
create service myLogs
on queue myQueue ([http://schemas.microsoft.com/SQL/Notifications/PostEventNotification]);
--log handler
create event notification myLogHandler
on server
for userconfigurable_0
to service 'myLogs', 'current database' ;
--message
EXEC master..sp_trace_generateevent @event_class = 82, @userinfo = N'test msg'
---transaction test
begin transaction
EXEC master..sp_trace_generateevent @event_class = 82, @userinfo = N'tran test msg'
rollback transaction
--receive message
declare @message_body xml;
receive top (1) @message_body = message_body
from myQueue
select @message_body
--display queue
select * from myQueue
That works fine for me though I needed to wait a few moments and run the receive from queue bit again before I saw anything.
Perhaps you need to
ENABLE_BROKERon the database.(Warning: Will kill existing connections to the DB)