采用ADO控件连接Sql数据库,使用存储过程时发现如下问题:
    在执行存储过程时,若第一条语句出错,则ADO可以捕捉到错误,
    若第一条无错,而其他语句出错时,则无法捕捉到错误,
请问该如何处理?

解决方案 »

  1.   

    try
    adoconnection1.beginstran;
    do.....
    adoconnection.commitstran;
    except
    adoconnection1.rollbacktran;  //显示错误
    for I := 0 to adoconnection1.Errors.Count - 1 do
        begin
          case AParam.AConnection.Errors[I].NativeError of
            547  : begin
                     if pos('insert',AParam.AConnection.Errors[I].Description) > 0 then
                     begin
                       //'外键约束insert,delete,update';
                       if sErrText <> '' then sErrText := sErrText + #13;
                       sErrText := sErrText + 's';
                     end
                     else
                     if pos('delete',AParam.AConnection.Errors[I].Description) > 0 then
                     begin
                       if sErrText <> '' then sErrText := sErrText + #13;
                       sErrText := sErrText + 's';
                     end
                     else
                     if pos('update',AParam.AConnection.Errors[I].Description) > 0 then
                     begin
                       if sErrText <> '' then sErrText := sErrText + #13;
                       sErrText := sErrText + 's';
                     end;
                   end;//end of 547        945  : begin
                     if sErrText <> '' then sErrText := sErrText + #13;
                     sErrText := sErrText + '您的内存不足!';
                   end;//end of 945        4850 : begin
                     if sErrText <> '' then sErrText := sErrText + #13;
                     sErrText := sErrText + '数据库表被锁定!';
                   end;//end of 1204        2627 : begin
                     if sErrText <> '' then sErrText := sErrText + #13;
                     sErrText := sErrText + '输入的关键属性值已经存在!';
                   end;//end of 2627        7303 : begin
                     if sErrText <> '' then sErrText := sErrText + #13;
                     sErrText := sErrText + '网络初始化失败!请检查网络设置!';
                   end;//end of 7303        10024: begin
                     if sErrText <> '' then sErrText := sErrText + #13;
                     sErrText := sErrText + '网络连接超时!请检查网络设置!';
                   end;//end of 10024        else   begin
                     if
                   end;
          end;//end of case    end;//end of for
        //最后显示错误信息sErrText 
    end;
      

  2.   

    你在存储过程里.begin tran
    set nocount on //加一句 
    ....commit
    set nocount off //加一句
      

  3.   

    同意上面.
    在存储过程里可以直接判断@@Error值, 不等于0就回滚,并返回这个错误值.