在SQL Server中批处理结束时检测到未提交的事务

时间:2014-08-01 06:22:43

标签: sql-server vb.net

我遇到了一个问题:在SQL Server中批处理结束时检测到未提交的事务。我尝试使用SQL Server管理工作室运行该过程,该过程正在运行,但是当我在VB.Net中调用该过程时,它显示了erroe消息:在批处理结束时检测到未提交的事务。我的程序如下:

GO 
SET ANSI_NULLS ON  
GO 
SET QUOTED_IDENTIFIER ON 
GO 
alter PROCEDURE [dbo].[SP_EN_PROD_PLAN_MAINT] 
@pid VARCHAR(10), 
@pday varchar(2), 
@pMonth varchar(2), 
@pYear varchar(4), 
@pid_mm_product bigint, 
@pID_MM_RAWMATERIALDTL bigint, 
@pID_MM_Machine bigint, 
@pOperate_Duration decimal(18,2), 
@pStop_Duration decimal(18,2), 
@pInput_Per_Hour decimal(18,2), 
@pOutput_Per_Hour decimal(18,2), 
@pEstimated_Total_Input decimal(18,2), 
@pEstimated_Total_Output decimal(18,2), 
@prectype varchar(1), 
@pdatatype varchar(1), 
@pcreatedby varchar(30), 
@pcreatedloc varchar(30), 
@return_value bigint output, 
@msg varchar(300) output 
AS 
BEGIN TRY 
SET NOCOUNT ON; 
SET XACT_ABORT ON 
SET @return_value = 0;

IF @prectype = '5'
    BEGIN
        UPDATE EN_PROD_PLAN
        SET REC_TYPE = @prectype,
        DATA_TYPE = @pdatatype,
        UPDATED_BY = @pcreatedby,
        UPDATED_DATE = GETDATE(),
        UPDATED_LOC = @pcreatedloc
        WHERE ID_EN_PROD_PLAN = @pid;

        IF @@ROWCOUNT = 1
            BEGIN
                SET @return_value = @pid;
            END;
    END;

IF @prectype = '3'
    BEGIN
        UPDATE EN_PROD_PLAN
        SET Operate_Duration = @pOperate_Duration,
        Stop_Duration = @pStop_Duration,
        Input_Per_Hour = @pInput_Per_Hour,
        Output_Per_Hour = @pOutput_Per_Hour,
        Estimated_Total_Output = @pEstimated_Total_Output,
        Estimated_Total_Input = @pEstimated_Total_Input,
        ID_MM_RAWMATERIALDTL = @pID_MM_RAWMATERIALDTL,
        REC_TYPE = @prectype,
        DATA_TYPE = @pdatatype,
        UPDATED_BY = @pcreatedby,
        UPDATED_DATE = GETDATE(),
        UPDATED_LOC = @pcreatedloc
        WHERE day = @pday
        and  Month = @pMonth
        and  Year = @pYear
        and  id_mm_product = @pid_mm_product
        and  ID_MM_Machine = @pID_MM_Machine;

        IF @@ROWCOUNT = 1
            BEGIN
                SET @return_value = @pid;
            END;
    END;

IF @prectype = '1'
    BEGIN
        IF EXISTS(SELECT ID_EN_PROD_PLAN FROM EN_PROD_PLAN (NOLOCK) WHERE upper(day) = upper(@pday) and upper(month) = upper(@pMonth)  and upper(Year) = upper(@pYear)  and upper(id_mm_product) = upper(@pid_mm_product)  and upper(ID_MM_Machine) = upper(@pID_MM_Machine)   AND REC_TYPE <> '5' and Data_Type = @pdatatype)
            BEGIN 
                UPDATE EN_PROD_PLAN
                        SET Operate_Duration = @pOperate_Duration,
                        Stop_Duration = @pStop_Duration,
                        Input_Per_Hour = @pInput_Per_Hour,
                        Output_Per_Hour = @pOutput_Per_Hour,
                        Estimated_Total_Output = @pEstimated_Total_Output,
                        Estimated_Total_Input = @pEstimated_Total_Input,
                        ID_MM_RAWMATERIALDTL = @pID_MM_RAWMATERIALDTL,
                        REC_TYPE = @prectype,
                        DATA_TYPE = @pdatatype,
                        UPDATED_BY = @pcreatedby,
                        UPDATED_DATE = GETDATE(),
                        UPDATED_LOC = @pcreatedloc
                        WHERE day = @pday
                        and  Month = @pMonth
                        and  Year = @pYear
                        and  id_mm_product = @pid_mm_product
                        and  ID_MM_Machine = @pID_MM_Machine
                        and  REC_TYPE <> '5' 
                        and  Data_Type = @pdatatype
                        ;

                        IF @@ROWCOUNT = 1
                            BEGIN
                                SET @return_value = 1;
                            END;
            END;
        ELSE
            BEGIN
                IF EXISTS(SELECT ID_EN_PROD_PLAN FROM EN_PROD_PLAN (NOLOCK) WHERE upper(day) = upper(@pday) and upper(month) = upper(@pMonth)  and upper(Year) = upper(@pYear)  and upper(id_mm_product) = upper(@pid_mm_product)  and upper(ID_MM_Machine) = upper(@pID_MM_Machine)   AND REC_TYPE = '5' and Data_Type = @pdatatype)
                    BEGIN
                        UPDATE EN_PROD_PLAN
                        SET Operate_Duration = @pOperate_Duration,
                        Stop_Duration = @pStop_Duration,
                        Input_Per_Hour = @pInput_Per_Hour,
                        Output_Per_Hour = @pOutput_Per_Hour,
                        Estimated_Total_Output = @pEstimated_Total_Output,
                        Estimated_Total_Input = @pEstimated_Total_Input,
                        ID_MM_RAWMATERIALDTL = @pID_MM_RAWMATERIALDTL,
                        REC_TYPE = @prectype,
                        DATA_TYPE = @pdatatype,
                        UPDATED_BY = @pcreatedby,
                        UPDATED_DATE = GETDATE(),
                        UPDATED_LOC = @pcreatedloc
                        WHERE day = @pday
                        and  Month = @pMonth
                        and  Year = @pYear
                        and  id_mm_product = @pid_mm_product
                        and  ID_MM_Machine = @pID_MM_Machine
                        AND  REC_TYPE = '5' 
                        and  Data_Type = @pdatatype;

                        IF @@ROWCOUNT = 1
                            BEGIN
                                SET @return_value = 1;
                            END;
                    END;
                ELSE
                    BEGIN

                        INSERT INTO EN_PROD_PLAN (day,Month,Year,id_mm_product,ID_MM_RAWMATERIALDTL,ID_MM_Machine,
                        Operate_Duration,Stop_Duration,Input_Per_Hour,Output_Per_Hour,Estimated_Total_Output,Estimated_Total_Input,
                        REC_TYPE,DATA_TYPE,CREATED_BY,CREATED_DATE,CREATED_LOC,UPDATED_BY,UPDATED_DATE,UPDATED_LOC)
                        VALUES (@pday,@pMonth,@pYear,@pid_mm_product,@pID_MM_RAWMATERIALDTL,@pID_MM_Machine,
                        @pOperate_Duration,@pStop_Duration,@pInput_Per_Hour,@pOutput_Per_Hour,@pEstimated_Total_Output,@pEstimated_Total_Input,
                        @prectype,@pdatatype,@pcreatedby,GETDATE(),@pcreatedloc,@pcreatedby,GETDATE(),@pcreatedloc);

                        IF @@ROWCOUNT = 1
                            BEGIN
                                SET @return_value = @@IDENTITY;
                            END;

                    END;
            END;
    END;

SET @return_value = ISNULL(@return_value,0);

END TRY
BEGIN CATCH
SET @return_value = 0;
SET @msg = Convert(varchar(3000),' ERROR - ' + ERROR_MESSAGE());
END CATCH;

0 个答案:

没有答案