alter proc g_modifyWealth
@userID int,
@points int,
as
begin tran
update ....
insert into ...
commit tran请问,我在程序中(ASP.net)中调用这个stored procedure之后,如何得知它被正确执行了?如果有错误,如何rollback呢?

解决方案 »

  1.   

    alter proc g_modifyWealth 
    @msg varchar(10) output,
    @userID int, 
    @points int, 
    as  
    begin tran  
    update .... 
    if @@error<>0
       goto msg
    insert into ... 
    if @@error<>0
       goto msg
    commit tran
     set @msg='true'
     return
    msg:
    begin
       set @msg ="false"
       rollback tran
        return
    end
      

  2.   

    alter proc g_modifyWealth
        @userID int,
        @points int,
    as
    begin
        begin tran
            update ....
            if @@Error<>0 insert into ...
        if @@Error<>0
           commit tran
        else
           rollback tran
    end
    go
    在ASP.NET端只要读取返回值不为空,或者不为0就可以知道是否成功执行了.
      

  3.   

    2000:
    alter proc g_modifyWealth
        @userID int,
        @points int
    as
        begin tran
            update ....
    if @@error<>0
    goto error
            insert into ...
    if @@error<>0
    goto error
        commit tran
    return 0error:
    rollback tran
    return 1go
    調用:declare @i int
    exec @i=g_modifyWealth 參數1,參數2
    select @i--1時失敗,0時成功
    go
      

  4.   

      用@@error与@@rowcount函数判断执行情况,把执行情况REturn回应用程序,然后判断返回码...
      
      

  5.   

    alter proc g_modifyWealth
        @userID int,
        @points int,
    as
    begin
        begin tran
            update ....
            if @@Error=0 insert into ...
        if @@Error=0
           commit tran
        else
           rollback tran
    end
    go
    汗一个先,写顺手了...