Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » SQL Server »

Problema Rollback, Commit Transaction SQL server

Estas en el tema de Problema Rollback, Commit Transaction SQL server en el foro de SQL Server en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 10/09/2015, 07:56
 
Fecha de Ingreso: febrero-2015
Ubicación: Distrito Federal
Mensajes: 38
Antigüedad: 9 años, 2 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
  #2 (permalink)  
Antiguo 13/09/2015, 12:17
Avatar de Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Problema Rollback, Commit Transaction SQL server

y si movemos el begin try de lugar???

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 TRANSACTION  Tadd                
  24.      BEGIN TRY      
  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


http://stackoverflow.com/questions/1...l-server-2008\
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me
  #3 (permalink)  
Antiguo 05/10/2015, 15:00
 
Fecha de Ingreso: febrero-2015
Ubicación: Distrito Federal
Mensajes: 38
Antigüedad: 9 años, 2 meses
Puntos: 1
Respuesta: Problema Rollback, Commit Transaction SQL server

Gracias ya funcionó, lo resolvi modificando el store interno. Por cierto lo de cambiar de lugar el BEGIN TRANSACTION también funcionó.
Saludos!
  #4 (permalink)  
Antiguo 05/10/2015, 15:03
Avatar de Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 17 años, 8 meses
Puntos: 774
Respuesta: Problema Rollback, Commit Transaction SQL server

Que bien que te funciono
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me

Etiquetas: bases-de-datos-general, commit, rollback
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:30.