sqlserver清空service broker中的队列的语句分享

前端之家收集整理的这篇文章主要介绍了sqlserver清空service broker中的队列的语句分享前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="51539" class="copybut" id="copybut51539" onclick="doCopy('code51539')"> 代码如下:

<div class="codebody" id="code51539">
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

那么客户端接受到的消息如果没有处理,也会积攒在客户端队列中,其实就相当于许多未读邮件,我们可以使用以下脚本读取队列 ,读取后队列自动清空:
<div class="codetitle"><a style="CURSOR: pointer" data="43253" class="copybut" id="copybut43253" onclick="doCopy('code43253')"> 代码如下:
<div class="codebody" id="code43253">
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 ;

原文链接:https://www.f2er.com/mssql/63988.html

猜你在找的MsSQL相关文章