Saturday, January 2, 2010

MSSQL 2005 BEGIN TRANSACTION

BEGIN TRY

BEGIN TRANSACTION

// Code

COMMIT

END TRY


BEGIN CATCH

-- Whoops, there was an error
IF @@TRANCOUNT > 0
ROLLBACK

-- Raise an error with the details of the exception
DECLARE @ErrMsg nvarchar(4000), @ErrSeverity int, @Is_Error int

SELECT @ErrMsg = ERROR_MESSAGE(), @ErrSeverity = ERROR_SEVERITY(), @Is_Error =@@error

RAISERROR(@ErrMsg, @ErrSeverity, 1)

END CATCH

No comments:

Post a Comment