Hi i have one sp where i used try catch with transaction. below is the code
USE [Securtimeweb2.1]
GO
/****** Object: StoredProcedure [dbo].[UpdateCompany] Script Date: 7/6/2015 12:14:27 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
ALTER PROCEDURE [dbo].[UpdateCompany]
(
@CompanyCode varchar(max),
@NewCompCode varchar(max)=null,
@TRANSVAL VARCHAR(MAX)
)
as
BEGIN
BEGIN TRY
BEGIN TRAN @TRANSVAL
update BranchMaster set CompanyCode=@NewCompCode Where CompanyCode=@CompanyCode
COMMIT TRAN @TRANSVAL
END TRY
BEGIN CATCH
SELECT ERROR_MESSAGE() AS strMessage
ROLLBACK TRAN @TRANSVAL
END CATCH
END
then i use this code to run this sp in another query window
EXEC UpdateCompany '002','003','TRAN1'
so after using this in one another query window i am trying to rollback the transaction which is
DECLARE @TRAN VARCHAR(MAX)='TRAN1'
BEGIN TRAN @TRAN
ROLLBACK TRAN @TRAN
so here we can see i given some name for the transaction and trying to rollback with the same name but it's not getting rollback. Am i doing anything wrong here??