真的很郁闷:我的三层架构,数据库访问层使用的是 TADOConnection系列控件:TADOQuery、TADOStoredProc。数据库是MSSQL。今天无意中测试存储过程,发现存储过程中的事务回滚了,但RAISERROR返回的错误程序却捕获不到。存储过程示例如下:
alter procedure proc_test(
) as
begin
begin transaction
update job
set operatetime=getdate()
where id=4
raiserror ('保存失败aaa', 16, 1)
if (@@error = 0)
begin
commit transaction
return 1
end
else
begin
rollback transaction
raiserror ('保存失败', 16, 1)
return 0
end
end
使用 TADOStoredProc 执行,没有任何效果。Delphi XE 中代码如下:
procedure TForm2.Button2Click(Sender: TObject);
begin
with ADOStoredProc1 do
begin
ExecProc;
end;
end;
后来,我把驱动从 OLEDB 换成了ODBC,果然能捕获错误了。但又出现了新问题&#x