我想在asp.net頁面中使用sp。RAISERROR和ROLLBACK TRANSACTION
如何顯示sp中的錯誤消息到asp.net中?
任何通過調用sp在asp.net中執行任務的DAL屬性示例?
在sp中使用RAISERROR和ROLLBACK TRANSACTION之間是否存在任何衝突?
ALTER PROCEDURE [dbo].[Cyrex_ChangeUsername]
@oldName nvarchar(128),
@newName nvarchar(128)
AS
declare @error_var int, @rowcount_var int
declare @newNameCount int
begin transaction
select @newNameCount = count(*)
from Users
where Username = ltrim(rtrim(@newName))
if @newNameCount > 0
begin
RAISERROR('Username already exists. @newName=%s', 10, 1, @newName)
ROLLBACK TRANSACTION
RETURN
end
update Users
set Username = ltrim(rtrim(@newName))
where Username = ltrim(rtrim(@oldName))
SELECT @error_var = @@ERROR, @rowcount_var = @@ROWCOUNT
IF @rowcount_var <> 1 OR @error_var <> 0
BEGIN
RAISERROR('Could not Update User.Username. @oldName=%s', 10, 1, @oldName)
ROLLBACK TRANSACTION
RETURN
END
update aspnet_Users
set
Username = @newName,
LoweredUserName = LOWER(@newName)
where LoweredUserName = LOWER(@oldName)
SELECT @error_var = @@ERROR, @rowcount_var = @@ROWCOUNT
IF @rowcount_var <> 1 OR @error_var <> 0
BEGIN
RAISERROR('Could not Update aspnet_Users.Username. @oldName=%s', 10, 1, @oldName)
ROLLBACK TRANSACTION
RETURN
END
Commit transaction
請問SQL Server的版本是? – gbn 2011-02-03 06:44:49