0

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.

niton
  • 8,771
  • 21
  • 32
  • 52
spender
  • 117,338
  • 33
  • 229
  • 351
  • 2
    Can you change the call to DeleteUser( ..., true ) ? – Bob Kaufman Oct 02 '09 at 15:26
  • Nice one Bob- you should put this as an answer. – RichardOD Oct 02 '09 at 15:28
  • Yes, that's the correct answer, Bob :) However, having run with the false parameter for a while, we've got a aspnetdb full'o'junk. That's what this question is about. – spender Oct 02 '09 at 15:33
  • @RichardOD - I was going back and forth on that one. There were two strikes against it as an answer: first, it's as much a question as an answer. Second, I'm implying that @spender could qualify his original question, thereby making my answer irrelevant to his need. – Bob Kaufman Oct 02 '09 at 15:44

2 Answers2

2

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
  • 28,883
  • 9
  • 61
  • 81
  • 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 Oct 02 '09 at 16:07
1

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
  • 6,524
  • 6
  • 37
  • 60