当前位置: 代码迷 >> Sql Server >> 报 ROLLBACK TRANSACTION 请求没有对应的 BEGIN TRANSACTION。 这有关问题咋修改
  详细解决方案

报 ROLLBACK TRANSACTION 请求没有对应的 BEGIN TRANSACTION。 这有关问题咋修改

热度:516   发布时间:2016-04-27 12:56:11.0
报 ROLLBACK TRANSACTION 请求没有对应的 BEGIN TRANSACTION。 这问题咋修改?
SQL code
   create proc usp_CloseEvent                           @UserGUID VARCHAR(40), --当前处理人的GUID                         @EventGUID VARCHAR(40),--事件单GUID                         @Hb VARCHAR(40), --汇报人                          @Jzqk VARCHAR(40), --事件单状况                         @remarks VARCHAR(4000), --处理说明                         @CloseCode VARCHAR(40),--关闭代码                        @EventQy VARCHAR(40),--事件起因                       @FwMethod VARCHAR(10),--服务方式                       @FeedBack VARCHAR(4000), --反馈意见             @stamp VARCHAR(100),     @strET VARCHAR(50),     @strE1 VARCHAR(50),              @strE2 VARCHAR(50),              @strE3 VARCHAR(50)                                AS                         DECLARE @count int                           DECLARE @strDepartment VARCHAR(40)                         DECLARE @strGW VARCHAR(20)                         DECLARE @date VARCHAR(24)                 DECLARE @tstamp bigint                                  begin                            SET @date = getdate()                          SET @count =0                   set xact_abort ON                                  SELECT   @strDepartment=CONVERT(varchar(40),DepartmentGUID),@strGW =JobTitle FROM myuser WHERE USERGUID = @UserGUID                  SELECT   @tstamp =convert(bigint,@stamp)                              BEGIN TRANSACTION                                                        BEGIN                            ---插入数据到处理过程                            INSERT INTO Itsm_ProcessReport (ProcessGUID,EventGUID,ProcessTime,ProcessContent,Hander,Receiver,Remarks) VALUES (newid(),@EventGUID,@date,'关闭事件单',@Hb,'',@remarks)                            SET @count = @count + @@ERROR                     IF @count <> 0                   BEGIN                    GOTO ERRORHANDLE                   END                    END                            BEGIN                            ---更新事件单信息                           UPDATE Itsm_EventInfo SET EventStatus  = @Jzqk,OldStatus= @Jzqk, EventQy = @EventQy ,FwMethod = @FwMethod , CloseCode = @CloseCode , FeedBack = @FeedBack, CloseTime = @date , CloserGUID = @UserGUID,[email protected],[email protected],[email protected]2,[email protected] WHERE [email protected]  AND CONVERT(bigint,EventStamp) = @tstamp                        IF  @@rowcount=0                    BEGIN                     GOTO ERRORBF                    END                                   SET @count = @count + @@ERROR                    IF @count <> 0                    BEGIN                     GOTO ERRORHANDLE                    END                             END                                         IF @count=0                   begin                    COMMIT TRANSACTION                                SELECT  'SUCCESS'                   end                                         ERRORHANDLE:                   begin                    ROLLBACK TRANSACTION                    SELECT 'FAILED'                   END                                      ERRORBF:                   begin                    ROLLBACK TRANSACTION                    SELECT 'BF'                   end                  END            


------解决方案--------------------
这一段加上return

SQL code
    IF @count=0                   begin                    COMMIT TRANSACTION                                SELECT  'SUCCESS'      RETURN                 end
------解决方案--------------------
try this,
SQL code
create proc usp_CloseEvent                           @UserGUID VARCHAR(40), --当前处理人的GUID                         @EventGUID VARCHAR(40),--事件单GUID                         @Hb VARCHAR(40), --汇报人                          @Jzqk VARCHAR(40), --事件单状况                         @remarks VARCHAR(4000), --处理说明                         @CloseCode VARCHAR(40),--关闭代码                        @EventQy VARCHAR(40),--事件起因                       @FwMethod VARCHAR(10),--服务方式                       @FeedBack VARCHAR(4000), --反馈意见             @stamp VARCHAR(100),     @strET VARCHAR(50),     @strE1 VARCHAR(50),              @strE2 VARCHAR(50),              @strE3 VARCHAR(50)                                AS                         DECLARE @count int                           DECLARE @strDepartment VARCHAR(40)                         DECLARE @strGW VARCHAR(20)                         DECLARE @date VARCHAR(24)                 DECLARE @tstamp bigint                                  begin                            SET @date = getdate()                          SET @count =0                   set xact_abort ON                                  SELECT   @strDepartment=CONVERT(varchar(40),DepartmentGUID),@strGW =JobTitle FROM myuser WHERE USERGUID = @UserGUID                  SELECT   @tstamp =convert(bigint,@stamp)                              BEGIN TRANSACTION                                                        BEGIN                            ---插入数据到处理过程                            INSERT INTO Itsm_ProcessReport (ProcessGUID,EventGUID,ProcessTime,ProcessContent,Hander,Receiver,Remarks) VALUES (newid(),@EventGUID,@date,'关闭事件单',@Hb,'',@remarks)                            SET @count = @count + @@ERROR                     IF @count <> 0                   BEGIN                    GOTO ERRORHANDLE                   END                    END                            BEGIN                            ---更新事件单信息                           UPDATE Itsm_EventInfo SET EventStatus  = @Jzqk,OldStatus= @Jzqk, EventQy = @EventQy ,   FwMethod = @FwMethod , CloseCode = @CloseCode , FeedBack = @FeedBack, CloseTime = @date ,    CloserGUID = @UserGUID,[email protected],[email protected],[email protected],[email protected]    WHERE [email protected]  AND CONVERT(bigint,EventStamp) = @tstamp                        IF  @@rowcount=0                    BEGIN                     GOTO ERRORBF                    END                                   SET @count = @count + @@ERROR                    IF @count <> 0                    BEGIN                     GOTO ERRORHANDLE                    END                             END                                         IF @count=0                   begin                    COMMIT TRANSACTION                                SELECT  'SUCCESS'                   end                   return                      ERRORHANDLE:                   begin                    ROLLBACK TRANSACTION                    SELECT 'FAILED'                   END                                      ERRORBF:                   begin                    ROLLBACK TRANSACTION                    SELECT 'BF'                   end                  END
  相关解决方案