views:

53

answers:

2

After calling method

_membershipProvider.DeleteUser(user.UserName, false);

where where the second parameter (false) is deleteAllRelatedData, orphaned entries are left in the database (aspnet_Users table and probably more). What is the best practice for cleaning these up?

EDIT: The user management code is already changed to now use true as the second param, but it's left a db full of junk entries. I'm wondering how best to clean these up. I'm currently looking at the sp provided with the database dbo.aspnet_Users_DeleteUser puzzling over the parameter @TablesToDeleteFrom int wondering exactly what it means. Looks like some sort of bitmask.

+2  A: 

I guess you'd have a choice of Cascade delete or write something that runs as a job periodically.

Or better yet do as stated in Bob's comment!

Update- as it sounds like you have now stopped this from occuring, just write a SQL Script to detect the orphaned records, then turn it into a DELETE statement.

RichardOD
I've added to my question... there are so many FK constraints in place that doing this turns out to be quite an arduous task. I'm looking at the supplied SP aspnet_Users_DeleteUser, which seems to have most of this "detection" already in place.
spender
+1  A: 

If you want to leave no orphan entries then you should set the second parameter (deleteAllRelatedData) to true. It will remove all related and child data.

http://msdn.microsoft.com/en-us/library/system.web.security.membershipprovider.deleteuser.aspx

tucaz
Sadly the junk is already there. Looking for a nifty way to delete it all.
spender