BizTalk ESB: Cleaning/Purge ESBExceptionDb for Fault Messages

Good to know!

Kelology

This is a handy SQL script created to clean up/purge ESBExceptionDb database for fault messages for particular days. This has been created only for development & testing purpose and is suggested not to run in Production environment unless you understand the use and circumstances. You can also schedule this as job once tested and verified the behavior of the script.

USE [EsbExceptionDb]
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[x_Delete_ESB_Faults]') AND type in (N'P', N'PC'))
DROP PROCEDURE [dbo].[x_Delete_ESB_Faults]
GO

USE [EsbExceptionDb]
GO

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[x_Delete_ESB_Faults]
    @DaysToKeep    INT = 7
AS
BEGIN
/*
=============================================
Example:
EXEC [dbo].[x_Delete_ESB_Faults] @DaysToKeep = 1
=============================================
*/
    DECLARE @currentDateTime DATETIME, @deleteFromDateTime DATETIME;

    SET @currentDateTime = GETUTCDATE();
    SET @deleteFromDateTime = @currentDateTime - @DaysToKeep;
    SET NOCOUNT ON;

    /*Deleting…

View original post 334 more words

Leave a comment