我在MS SQL 中写了一个存储过程
   PROCEDURE  PURB01
  
as  begin tran  --开台事务  declare DS_Cursor cursor For select  * from table
  open DS_Cursor  fetch next from DS_Cursor into  xx                             
  
 while @@fetch_status=0
    
begin
  update TABLE_B set xxx where xxx
  fetch next from DS_Cursor into xx                                
end
  close DS_Cursor
  DEALLOCATE DS_Cursor   IF @@ERROR <> 0  
  begin
    ROLLBACK  TRANSACTION 
  end
  else
    commit tran 
go过程通过DELPHI 程序调用,如果用户在在调用过程中,退出程序(过程未执行完成,如过程执行时间太长,程序停止了响应,用户结束了程序),这时事务没有回滚也没有提交,现在的问题是select * from TABLE_B 查询不出数据,要将SQL SERVER 服务重启一下才行.问下这种问题如何解决.

解决方案 »

  1.   


        begin   tran --开始事务     declare  DS_Cursor cursor For select * from table 
        open   DS_Cursor     fetch next from DS_Cursor into xx  
        
    while   @@fetch_status=0 
            
    begin 
    update TABLE_B set xxx where xxx  IF   @@ERROR <> 0     
    begin 
    ROLLBACK  TRANSACTION  
    close   DS_Cursor 
    DEALLOCATE   DS_Cursor   
    end fetch next from DS_Cursor into   xx
    end     close  DS_Cursor 
        DEALLOCATE  DS_Cursor       IF   @@ERROR <> 0     
        begin 
            ROLLBACK   TRANSACTION   
        end 
        else 
            commit   tran