Quantcast
Channel: SQL Service Broker forum
Viewing all articles
Browse latest Browse all 461

Service Broker conversations won't close [SOLVED]

$
0
0

Below is the code currently used (not made by me). Our tempdb was filling up incredibly fast and when me and my coworker looked into it, we discovered that it's likely related to the service broker. One issue I found is I ran this query:

select TOP 1000000 *
	from sys.conversation_endpoints

And none of the messages have Disconnected or Closed. Everything is either STARTED_INBOUND or CONVERSING. The query below is what i believe is affecting it. I tried adding a lifetime to 5 minutes and even adding an END CONVERSATION. Everything errors out instead. Any help would be appreciated.

GO
/****** Object:  StoredProcedure [dbo].[usp_SendAuditData]    Script Date: 12/23/2015 14:53:41 ******/

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- stored procedure that sends the audit data to the be audited
ALTER PROCEDURE [dbo].[usp_SendAuditData]
(
	@AuditedData XML
)
AS
BEGIN
	SET NOCOUNT ON;
	SET XACT_ABORT OFF;
	BEGIN TRY
		DECLARE @dlgId UNIQUEIDENTIFIER, @dlgIdExists BIT

		SELECT @dlgIdExists = 1

		-- Check if our database already has a dialog id that was previously used
		-- Why reusing conversation dialogs is a good this is explaind here
		-- http://blogs.msdn.com/remusrusanu/archive/2007/04/24/reusing-conversations.aspx
		-- very well
		SELECT	@dlgId = DialogId
		FROM	MasterAuditDatabase.dbo.AuditDialogs AD
		WHERE	AD.DbId = DB_ID()
		IF 	@dlgId IS NULL
		BEGIN
			SELECT @dlgIdExists = 0
		END

		-- Begin the dialog, either with existing or new Id
		BEGIN DIALOG @dlgId
			FROM SERVICE    [//Audit/DataSender]
			TO SERVICE      '//Audit/DataWriter',
							-- this is a MasterAuditDatabase Service Broker Id (change it to yours)
							'F771D95A-DFAE-47DC-BE02-9F29272C8206'
			ON CONTRACT     [//Audit/Contract]
		WITH ENCRYPTION = OFF;--, LIFETIME = 300;

		-- add our db's dialog to AuditDialogs table if it doesn't exist yet
		IF @dlgIdExists = 0
		BEGIN
			INSERT INTO MasterAuditDatabase.dbo.AuditDialogs(DbId, DialogId)
			SELECT	DB_ID(), @dlgId
		END
		--SELECT @AuditedData

		-- Send our data to be audited
		;SEND ON CONVERSATION @dlgId
		MESSAGE TYPE [//Audit/Message] (@AuditedData)
	END TRY
	BEGIN CATCH
		INSERT INTO AuditErrors (
				ErrorProcedure, ErrorLine, ErrorNumber, ErrorMessage,
				ErrorSeverity, ErrorState, AuditedData)
		SELECT	ERROR_PROCEDURE(), ERROR_LINE(), ERROR_NUMBER(), ERROR_MESSAGE(),
				ERROR_SEVERITY(), ERROR_STATE(), ISNULL(@AuditedData, '')
	END CATCH
	--END CONVERSATION @dlgId
END





Viewing all articles
Browse latest Browse all 461

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>