存储过程错误处理
CREATE proc P_Insert_New_BookTitle_2K
(@TitleName nvarchar(128),
@Price money,
@au_fname nvarchar(32),
@au_name nvarchar(64),
@CommissionRating int)
as
declare @err int,
@tablename sysname
begin transaction
insert dbo.Titles (TitleName, Price)
values (@TitleName, @Price)
select @err = @@error
if @err <> 0
begin
select @tablename = 'titles '
GOTO ERROR_HANDLER
end
insert dbo.Authors (au_fname, au_lname, TitleID, CommissionRating)
values (@au_fname, @au_fname, @@IDENTITY, @CommissionRating)
if @err <> 0
begin
select @tablename = 'authhors '
GOTO ERROR_HANDLER
end
GOTO EXIT_Proc
ERROR_HANDLER:
ROLLBACK TRANSACTION
-- Log the error
insert dbo.Application_Error_Log (tableName, UserName, errorNumber, errorSeverity, errorState)
values (@tableName, suser_sname(), @err, 0, 0)
EXIT_Proc:
commit tran
这个存储过程我在我本机上单步调试时错误处理根本就没有执行呀!而且事务也没有回滚.
------解决方案--------------------存儲過程沒問題