I want to call my ms sql stored procedure from nservicebus handler and I wonder if I still need to use something like
CREATE PROCEDURE [dbo].[proc_fd_SomeEntitySyncRawWithStage]
AS BEGIN
BEGIN TRY
BEGIN TRANSACTION
-- Batch of inserts and updates that I want to keep transactional
COMMIT TRANSACTION;
END TRY BEGIN CATCH
ROLLBACK TRANSACTION;
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;
SELECT
@ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();
RAISERROR (@ErrorMessage,
@ErrorSeverity,
@ErrorState
);
END CATCH; END
Do I really need all this TRY BEGIN TRAN... CATCH ROLLBACK .. or SET XACT_ABORT ON... stuff to rollback my transaction or NServiceBus will rollback it in case of any sql exception in message handler ?
P.S. Keeping in mind that:
"If a run-time statement error (such as a constraint violation) occurs in a batch, the default behavior in the Database Engine is to roll back only the statement that generated the error"
and
"When SET XACT_ABORT is OFF, in some cases only the Transact-SQL statement that raised the error is rolled back and the transaction continues processing."