function TfServer.pUpdateData():integer;//修改数据
    var
      q1:TQuery;
    begin
      result:=-1;
      dbDynamic.StartTransaction ;
      try
        try
          q1:=TQuery.Create(nil);
          with q1 do
          begin
          databasename:=dbDyNamic.DatabaseName ;
          s:='update My_table set ....';          
          sql.add(s);          
          EXECSQL;
          end;
        except
          on Exception do
          begin
          dbdyNamic.Rollback ;//出错回滚
          raise;
          end;
        end;
      finally
        q1.Active :=false;
        q1.Free;
      end;
      dbdyNamic.Commit ;
      result:=0;
    end;
    
    如果更新数据出错,比如字段值太长,EXECSQL处就会捕捉到异常,并会抛出异常,必须点击弹出窗口程序才能继续运行;
    如果我不要抛出异常,使程序正常运行(作为服务器,出现异常的用户,终止这次更新操作,但不能影响到别的用户操作),改如何做?谢先!!!

解决方案 »

  1.   

    不要raise就没错误提示了http://lysoft.7u7.net
      

  2.   

    不要抛出就可以了
    比如
    try
     //....
    except
     //do nothing!!
    end;
      

  3.   

    如果去掉raise,则会出现提示:“No user transaction is currently in progress”
      

  4.   

    dbdyNamic.Commit ;//移到这里搞定
            except
              on Exception do
              begin
                dbdyNamic.Rollback ;//出错回滚
                //raise;
              end;
            end;
          finally
            q1.Active :=false;
            q1.Free;
          end;
          
          result:=0;
        end;