DotNetNuke Powered!
          
John Mitchell's (mostly DotNetNuke) Blog - Error: User Accounts is currently unavailable.
 Wednesday, June 07, 2006

This error is usually due to the aspnet_ membership tables being out of sync with the DotNetNuke Users table.

Here's a way to go about deleting those orphaned Users from the aspnet_* memberRole tables

There are a lot of Referential Integrity constraints on the aspnet_ membership tables that makes it kind of difficult to delete them directly.

This SQL will loop through them all and delete any that are not in the DNN Users table:

DECLARE @UserName varchar (50)

--get a cursor to hold all the orphaned users
--that are in aspnet_Users table that are not in the DNN Users table
DECLARE users_cursor CURSOR FOR
SELECT au.UserName FROM aspnet_Users au
LEFT OUTER JOIN Users u on au.UserName = U.UserName
WHERE U.UserName is null

OPEN users_cursor

-- Perform the first fetch.
FETCH NEXT FROM users_cursor INTO @UserName

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
--delete the user from all the aspnet_* tables that it may be in
--one at a time to avoid referrential integrity constraints

delete aspnet_Membership where UserId =
(select am.UserId from aspnet_Membership am inner join aspnet_Users au on am.UserId = au.UserId
where au.Username =@UserName)

delete aspnet_Profile where UserId =
(select ap.UserId from aspnet_Profile ap inner join aspnet_Users au on ap.UserId = au.UserId
where au.Username =@UserName)
delete aspnet_UsersInRoles where UserId
in (select uir.UserId from aspnet_UsersInRoles uir inner join aspnet_Users au on uir.UserId = au.UserId
where au.Username =@UserName)

delete from aspnet_Users where Username =@UserName

FETCH NEXT FROM users_cursor INTO @UserName
END

CLOSE users_cursor
DEALLOCATE users_cursor
GO

6/7/2006 6:35:08 AM (Central Standard Time, UTC-06:00)  #    Comments [9]