sqlserver清空service broker中的隊列的語句分享。本站提示廣大學習愛好者:(sqlserver清空service broker中的隊列的語句分享)文章只能為提供參考,不一定能成為您想要的結果。以下是sqlserver清空service broker中的隊列的語句分享正文
USE TestDB
declare @conversation uniqueidentifier
while exists (select 1 from sys.transmission_queue )
begin
set @conversation = (select top 1 conversation_handle from sys.transmission_queue )
end conversation @conversation with cleanup
end
那末客戶端接收到的新聞假如沒有處置,也會積累在客戶端隊列中,其實就相當於很多未讀郵件,我們可使用以下劇本讀取隊列 ,讀取後隊列主動清空:
USE TestDB
DECLARE @RecvReplyMsg NVARCHAR(100) ;
DECLARE @RecvReplyDlgHandle UNIQUEIDENTIFIER ;
BEGIN TRANSACTION ;
WHILE ( 1 = 1 )
BEGIN
WAITFOR
( RECEIVE TOP(1)
@RecvReplyDlgHandle = conversation_handle,
@RecvReplyMsg = message_body
FROM dbo.Test_TargetQueue
), TIMEOUT 1000 ;
END CONVERSATION @RecvReplyDlgHandle ;
SELECT @RecvReplyMsg AS ReceivedReplyMsg ;
END
COMMIT TRANSACTION ;