0
我試圖將用戶從系統中存在的自定義用戶表導入到.net成員資格提供程序表中。爲什麼我的存儲過程回滾我聲明它這樣做
我構建了一個小應用程序,刪除.net成員表中除我自己的帳戶以外的所有預先存在的用戶。我這樣寫,這樣每次運行應用程序時,它都會清除我添加的任何內容,並重新輸入所有用戶的數據。這個存儲過程在過去一直有效,但自從切換到SQL Server 2005 Enterprise的這個新實例以來,刪除事務一直在回滾。
這是存儲過程,用於在將用戶寫回到之前清除所有數據.net成員資格表。
ALTER PROCEDURE [dbo].[usp_ClearAllUsers]
AS
begin
DECLARE @UserID uniqueidentifier
set @UserID = (SELECT UserId
FROM dbo.aspnet_Users
where (UserName = 'gianluca.sirianni'))
begin
Delete from dbo.aspnet_Membership WHERE (dbo.aspnet_Membership.UserID != @UserID)
end
begin
Delete from dbo.aspnet_UsersInRoles WHERE (dbo.aspnet_UsersInRoles.UserID != @UserID)
end
begin
Delete from dbo.aspnet_Profile WHERE (dbo.aspnet_Profile.UserID != @UserID)
end
begin
Delete from dbo.aspnet_Users WHERE (dbo.aspnet_Users.UserID != @UserID)
end
end
有人可以提出爲什麼我的數據可能會回滾嗎?我在SQL語句中很流利,但不在服務器本身的事務處理上。
更新:
我將上述過程更改爲以下內容。它是否正確?
ALTER PROCEDURE [dbo].[usp_ClearAllUsers]
AS
BEGIN
DECLARE @UserID uniqueidentifier
SET @UserID = (SELECT UserId
FROM dbo.aspnet_Users
WHERE (UserName = 'gianluca.sirianni'))
BEGIN TRAN
DELETE FROM dbo.aspnet_Membership WHERE (dbo.aspnet_Membership.UserID != @UserID)
COMMIT TRAN
BEGIN TRAN
DELETE FROM dbo.aspnet_UsersInRoles WHERE (dbo.aspnet_UsersInRoles.UserID != @UserID)
COMMIT TRAN
BEGIN TRAN
DELETE FROM dbo.aspnet_Profile WHERE (dbo.aspnet_Profile.UserID != @UserID)
COMMIT TRAN
BEGIN TRAN
DELETE FROM dbo.aspnet_Users WHERE (dbo.aspnet_Users.UserID != @UserID)
COMMIT TRAN
END