此Sql Server存储过程为我提供了
错误:
(Transaction count after EXECUTE indicates a mismatching number of BEGIN and COMMIT statements. Previous count = 0, current count = 1.):
SQL:
DECLARE @MessageType sysname
DECLARE @ConversationHandle uniqueidentifier
DECLARE @RawRemittanceAdviceId int
DECLARE @ClrReturnCode int
DECLARE @WebServiceUrl nvarchar(512)
DECLARE @ErrorMessage nvarchar(MAX)
BEGIN
BEGIN TRANSACTION
WAITFOR (
RECEIVE TOP (1)
@MessageType = message_type_name
, @RawRemittanceAdviceId = message_body
, @ConversationHandle = conversation_handle
FROM [RawRATranslationChannel]
), TIMEOUT 5000 -- 5 seconds
IF (@@ROWCOUNT = 0)
BEGIN
ROLLBACK TRANSACTION
END
ELSE
BEGIN
-- Check for end of dialog messages
IF (@MessageType = 'http://schemas.microsoft.com/SQL/ServiceBroker/EndDialog')
BEGIN
END CONVERSATION @ConversationHandle
END
ELSE IF (@MessageType = 'http://schemas.microsoft.com/SQL/ServiceBroker/Error')
BEGIN
-- Handle the error
BEGIN
-- Add Error Message
UPDATE [dbo].[RawRemittanceAdvice]
SET DiagnosticMessage = N'Service Broker Error', ProcessingStatus = 2, LastUpdated = GETUTCDATE()
WHERE RawRemittanceAdviceId = @RawRemittanceAdviceId
END
END CONVERSATION @ConversationHandle
END
ELSE IF (@MessageType = 'TranslateRawRA')
-- Perform Translation of the Raw Remittance Advice
BEGIN
BEGIN TRY
SELECT @WebServiceUrl = SettingValue
FROM dbo.GlobalSettings
WHERE SettingName = N'TranslationWebServiceUrl'
-- Call CLR Sproc to perform Translation
EXEC @ClrReturnCode = [dbo].[TranslateRawRemittanceAdvice] @RawRemittanceAdviceId, @WebServiceUrl, @ErrorMessage OUTPUT
IF @ClrReturnCode = 0
BEGIN
-- Send Response
SEND ON CONVERSATION @ConversationHandle
MESSAGE TYPE [TranslateRawRAResponse]
(CAST(@RawRemittanceAdviceId AS NVARCHAR))
END
ELSE
BEGIN
-- Add Error Message
UPDATE [dbo].[RawRemittanceAdvice]
SET DiagnosticMessage = @ErrorMessage, ProcessingStatus = 2, LastUpdated = GETUTCDATE()
WHERE RawRemittanceAdviceId = @RawRemittanceAdviceId
END
END TRY
BEGIN CATCH
BEGIN
-- Add Error Message
UPDATE [dbo].[RawRemittanceAdvice]
SET DiagnosticMessage = ERROR_MESSAGE(), ProcessingStatus = 2, LastUpdated = GETUTCDATE()
WHERE RawRemittanceAdviceId = @RawRemittanceAdviceId
END
END CATCH
END CONVERSATION @ConversationHandle
END
COMMIT TRANSACTION
END
END
答案 0 :(得分:0)
请参阅以下变通方法以供参考: