Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/09/2015, 07:56
ferdave1904
 
Fecha de Ingreso: febrero-2015
Ubicación: Distrito Federal
Mensajes: 38
Antigüedad: 9 años, 3 meses
Puntos: 1
Problema Rollback, Commit Transaction SQL server

Saludos espero puedan ayudarme.
Resulta que tengo un procedimiento almacenado que me esta generando el siguiente error del SQL:

La solicitud ROLLBACK TRANSACTION no tiene la correspondiente BEGIN TRANSACTION.

El error en el store cuando uso el metodo ERROR_MESSAGE() es el Siguiente:

El recuento de transacciones después de EXECUTE indica un número no coincidente de instrucciones BEGIN y COMMIT. Recuento anterior = 1, recuento actual = 0. en la línea 0.

No entiendo porque si en realidad si tengo El respectivo Begin Transaction, Commit Transaction y Rollback Transaction. El Código es el siguiente:

Código SQL:
Ver original
  1. PROCEDURE [dbo].[addPosAndStore]
  2. @idStrClient AS VARCHAR(50),
  3. @statusList AS text,
  4. @nameList AS text,
  5. @posidList AS text,
  6. @nodesList AS text,
  7. @msg AS VARCHAR(200) output
  8. AS
  9. BEGIN
  10.     SET NOCOUNT ON
  11.     DECLARE @idClient BIGINT,
  12.              @idConstraint BIGINT,
  13.              @posidConstraint BIGINT,
  14.              @name  VARCHAR(100),
  15.              @posId  VARCHAR(100),
  16.              @businessIdNode  VARCHAR(100),
  17.              @STATUS tinyint,
  18.              @totalRows INT,
  19.              @counter INT,
  20.              @idHd BIGINT,
  21.              @idHierarchyData BIGINT,
  22.              @retValue INT
  23.      BEGIN TRY     
  24.      BEGIN TRANSACTION  Tadd               
  25.         SELECT * INTO #tstatus FROM Split(@statusList,',')
  26.         SELECT * INTO #tname FROM Split(@nameList,',')
  27.         SELECT * INTO #posid FROM Split(@posidList,',')
  28.         SELECT * INTO #nodes FROM Split(@nodesList,',')
  29.            
  30.         SET @totalRows = (SELECT COUNT(*) FROM #tstatus)
  31.         SET @counter = 0   
  32.         WHILE @counter <= @totalRows       
  33.         BEGIN      
  34.             SET @STATUS = CONVERT(TINYINT,(SELECT VALUE FROM #tstatus WHERE id = @counter))
  35.             SET @name = (SELECT VALUE FROM #tname WHERE id = @counter)
  36.             SET @posId = (SELECT VALUE FROM #posid WHERE id = @counter)
  37.             SET @businessIdNode = (SELECT VALUE FROM #nodes WHERE id = @counter)           
  38.             SET @idClient = (SELECT id FROM Client WHERE idStrClient = @idStrClient)
  39.  
  40.             EXEC   @retValue = [dbo].[addStore]
  41.                     @name = @name,
  42.                     @businessIdNode = @businessIdNode,
  43.                     @idClient = @idClient,
  44.                     @idHd = @idHd OUTPUT,
  45.                     @msg =  @msg output
  46.                        
  47.             SET @idHierarchyData = (SELECT @idHd)
  48.            
  49.             IF @idHierarchyData = -1 OR  @idHierarchyData IS NULL          
  50.                 RETURN             
  51.            
  52.             INSERT INTO TableConstraint (openingSchedule, closingSchedule,salesLimitByDay,salesAmountByDay,salesLimitByMonth,salesAmountByMonth) VALUES (NULL, NULL, 0.0, 0, 0.0, 0)
  53.             SET @posidConstraint =  (SELECT MAX(id) FROM TxnConstraint)
  54.            
  55.             INSERT INTO [POS]
  56.                    ([idClient],[idHierarchyData],[POSIdentifier],[TYPE],[STATUS],[idConstraint])
  57.              VALUES
  58.                    (@idClient,@idHierarchyData,@posId,0,@STATUS,@posidConstraint)                  
  59.                    SET @counter = @counter + 1                      
  60.         END                        
  61.         DROP TABLE #tname
  62.         DROP TABLE #tstatus
  63.         DROP TABLE #posid
  64.                                                    
  65.         COMMIT TRANSACTION Tadd
  66.         SET @msg = '00,Se han insertado los registros correctamente'
  67.     END TRY
  68.     BEGIN CATCH
  69.         SET @msg = '99,Ocurrio un Error: '+ERROR_MESSAGE()+' en la línea ' + CONVERT(NVARCHAR(255), ERROR_LINE() ) + '.'
  70.         ROLLBACK TRANSACTION Tadd
  71.     END CATCH
  72. END
  73. GO