0

我已经看过帖子并试图解决这个问题但无法解决。所以这里是代码。帮助解决同样的问题。

我有一个程序调用另一个程序。

来电程序:

ALTER PROCEDURE [dbo].[DadSaveMembership]
@PERSON AS [dbo].[Person_Master_Type] Readonly,
@ADDRESS AS [dbo].[Address_Master_Type] Readonly, 
@MEMBERSHIP AS [dbo].[Membership_Type] Readonly

AS
BEGIN

declare @pid int, @aid int, @CUR_PID int, @CUR_ADD int, @atype int, @created_by int
declare @created_date date

select @pid=person_id from @PERSON
select @aid=address_id from @ADDRESS

if(@pid=0)
begin
    INSERT INTO PERSON_MASTER (TITLE,FNAME,MNAME,LNAME,DOB,GENDER,MARITALSTATUS,MOBILE,EMAIL,CREATED_BY,CREATED_DATE)
    SELECT TITLE,FNAME,MNAME,LNAME,DOB,GENDER,MARITALSTATUS,MOBILE,EMAIL,CREATED_BY,CREATED_DATE FROM @PERSON
    SELECT @CUR_PID=MAX(PERSON_ID) FROM PERSON_MASTER
end
else
begin
    set @CUR_PID=@pid
end

if(@aid=0)
begin
    INSERT INTO ADDRESS_MASTER (ADDRESS1,ADDRESS2,ADDRESS3,CITY_ID,PINCODE,PHONE,CREATED_BY,CREATED_DATE)
    SELECT ADDRESS1,ADDRESS2,ADDRESS3,CITY_ID,PINCODE,PHONE,CREATED_BY,CREATED_DATE FROM @ADDRESS
    SELECT @CUR_ADD=MAX(ADDRESS_ID) FROM ADDRESS_MASTER
end
else
begin
    set @CUR_ADD=@aid
end



EXEC [dbo].[GET_DAD_COUNT_AID$IMPL$AUTO] @CUR_PID, "3", @CUR_ADD, @atype OUTPUT

INSERT INTO PERSON_MODULE_LINK (PERSON_ID,MODULE_ID,ADDRESS_ID,ADDRESS_TYPE,CREATED_BY,CREATED_DATE) 
VALUES (@CUR_PID,3,@CUR_ADD,@atype,@CREATED_BY,@CREATED_DATE)

END

另一个程序如下

ALTER PROCEDURE [dbo].[GET_DAD_COUNT_AID$IMPL$AUTO]  
@pid int,
@modid int,
@addrid int,
@return_value_argument int  OUTPUT
AS 

BEGIN

  SET  IMPLICIT_TRANSACTIONS  ON

  DECLARE
     @cnt int, 
     @cnt1 int


  SELECT @cnt1 = isnull(max(CAST(ADDRESS_HISTORY_DETAIL.ADDRESS_TYPE AS numeric(38, 10))), 0)
  FROM dbo.ADDRESS_HISTORY_DETAIL
  WHERE 
     ADDRESS_HISTORY_DETAIL.PERSON_ID = @pid AND 
     ADDRESS_HISTORY_DETAIL.MODULE_ID = @modid AND 
     ADDRESS_HISTORY_DETAIL.ADDRESS_ID = @addrid



  SELECT @cnt = isnull(max(CAST(PERSON_MODULE_LINK.ADDRESS_TYPE AS numeric(38, 10))), 0)
  FROM dbo.PERSON_MODULE_LINK
  WHERE 
     PERSON_MODULE_LINK.PERSON_ID = @pid AND 
     PERSON_MODULE_LINK.MODULE_ID = @modid AND 
     PERSON_MODULE_LINK.ADDRESS_ID = @addrid



  IF @cnt1 > @cnt
     BEGIN

        SET @return_value_argument = @cnt1+1

        RETURN 

     END
  ELSE 
     BEGIN

        SET @return_value_argument = @cnt+1

        RETURN 

     END

END

问题是调用 DadSaveMembership SP 时出现以下错误:超时已过期。在操作完成之前超时时间已过或服务器没有响应。那么,有什么问题呢?

4

1 回答 1

0

我怀疑问题出SET IMPLICIT_TRANSACTIONS ONGET_DAD_COUNT_AID$IMPL$AUTO存储过程中的命令。阅读MSDN会发现,通过设置命令并执行 SELECT 命令,会创建一个事务,但从未提交或回滚。您可以将原始 SP 包装在事务 BEGIN TRANSACTION+ COMMIT/ROLLBACK中,也可以一起删除该语句。

您还应该考虑替换这两个语句:

SELECT @CUR_ADD=MAX(ADDRESS_ID) FROM ADDRESS_MASTER
SELECT @CUR_PID=MAX(PERSON_ID) FROM PERSON_MASTER

用这些:

SELECT @CUR_ADD = SCOPE_IDENTITY()
SELECT @CUR_PID = SCOPE_IDENTITY()
于 2012-06-23T07:17:10.343 回答