Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Cleaning Up User AccountsCleaning Up User Accounts
Previous
 
Next
New Post
1/13/2007 7:20 PM
 
I'd like to clean up the users on one of the sites I host before moving them to a new database (whole other issue). I was going to delete anyone that hasn't logged on in more than a year but the only place I can find where the last login date is stored is in the aspnet_Memberships table. I can't find anywhere in the aspnet tables where the UserID matches the UserIDs from the Users table. Any ideas on how I can accomplish what I'm trying to do?
 
New Post
1/13/2007 7:43 PM
 

I guess you will need to join UserName on Users and aspnet_Users. Here is a script I got from Charles (not sure it was Charles) that deleted orphaned users. Maybe that helps:

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

 
New Post
1/13/2007 8:18 PM
 

Thanks Mariette, that definitely helps. It's not quite there but it's close enough that it kickstarted my brainfart in the right direction.

 
New Post
1/13/2007 8:25 PM
 
Yeah, I was trying something also. I think we also need to innerjoin also aspnet_profile with aspnet_Users. Then create a where on LastLogindate...
 
New Post
1/13/2007 8:35 PM
 

Initial testing looks like this works. Then you'd need to run the script you posted to clean up the aspnet tables.

DECLARE

 

--get a cursor to hold all the users have not logged in for more than a year

 

DECLARE

select

 

inner

 

OPEN

 

-- Perform the first fetch.

 

FETCH

 

-- Check @@FETCH_STATUS to see if there are any more rows to fetch.

 

WHILE

 

BEGIN

 

 

 

FETCH

 

END

CLOSE

 

DEALLOCATE

GO

 

@UserName varchar (50) users_cursor CURSOR FOR AU.UserName From Aspnet_users AU Join Aspnet_membership AM on AM.UserID = AU.UserID Where AM.LastLoginDate < '2006-01-01' users_cursor NEXT FROM users_cursor INTO @UserName @@FETCH_STATUS = 0DELETE Users WHERE Username=@UserName NEXT FROM users_cursor INTO @UserName users_cursor users_cursor
 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...Cleaning Up User AccountsCleaning Up User Accounts


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out