
while (select count(*) from auditlog.AuditQueue with (nolock)) > 0
    begin
    raiserror('Waiting for empty AuditQueue...', 0, 0) with nowait;
    waitfor delay '00:00:05';
    end
go

ALTER QUEUE [auditlog].[AuditQueue] 
WITH 
    STATUS = OFF, 
    RETENTION = OFF, 
    ACTIVATION (
        STATUS = OFF, 
        PROCEDURE_NAME = [auditlog].[usp_AuditProcessing], 
        MAX_QUEUE_READERS = 1, 
        EXECUTE AS N'kreta_tech_user'
    ), 
    POISON_MESSAGE_HANDLING (STATUS = ON) 
GO

TRUNCATE TABLE auditlog.DialogPool
GO