Try our conversational search powered by Generative AI!

Delete old users?


[For this project, we are using EPiServer Commerce 7.12.0]


Every time a cart is created, an anonymous user is also created in the commerce database (not the CMS database). I'd like to remove the users belonging to since-long deleted unused carts and old purchase orders, i.e. I don't want to remove all users there ("there" being the aspnet_* tables in the commerce database).

Since they are created in the commerce database, I can't use Membership to retrieve them, and CustomerContext.Current.GetAllContacts() only seem to retrieve users/contacts from the CMS database and not the commerce database.

Is there a way of retrieving those users and deleting them?

So far I have about 20 million anonymous users in the commerce database, and I want to delete the ones created more than 180 days ago.

Edited, Mar 20, 2018 17:14

I know I can do it directly in SQL, but I'm wondering if there is a way of doing it in code.

Mar 20, 2018 17:20


There is no builtin function to delete old users (IIRC then you can't even delete users, let alone do it in batch. You can delete contacts, but not users). If your purpose of doing that would be performance, then upgrading to latest version will yield much better return on investment.

If you do it for GDPR compliance then it can be much trickier. I'd suggest to contact our develop support for that.

Mar 21, 2018 10:24

It's not really a problem, but I like to keep a clean system :)

Those 20 million users consume about 11 GB of storage in the database, and it feels a bit wasteful to keep all those anonymous users when they aren't used for anything (users never log in to the commerce part of the site, so there should hopefully not be any personal information connected to those users (the shipping info should only be stored on the cart/purchase order)).

Mar 21, 2018 14:13

Hi Quan,

For GDPR purposes, how would you recommend deleting users to keep in line with the right to be forgotten?

Nov 02, 2018 11:45

I'm not an GDPR expert - far from it - but what I understand is that you can just delete that contact and that should be enough. The orders are "financial contracts" and therefore are exempted from GDPR rules. But again don't take my words for granted.

Nov 02, 2018 11:53

Thanks a lot. Will investigate a bit further, but it's already a good lead. have a gr8 friday!

Nov 02, 2018 12:01

Financial records are (at least in Sweden and Denmark) regulated by different laws which override GDPR. In Sweden you must keep the financial records for 7 years, and in Denmark 5 years, so you are legally obligated to keep those records for that amount of time.

An important thing a lot of people forget is that they also have to erase personal information from log files, which means that if a customers sends a "Right to be Forgotten", you have to erase their information from log4net (or other logging solution) logs as well.

I use Serilog for most of our logging (logging to a database), and tag each entry with something I can use to find the log entries with (such as an order number, or an e-mail address), and then finding log entries to remove is quite easily done.

Nov 02, 2018 12:03

Thanks for the extra info Patrick. Will keep that in mind. have a good one!

Nov 02, 2018 12:17

Hi again guys,

UserManager<>.Delete(user) works fine. Contact is succesfully deleted from the cms.

However, i am using CustomerContext.CurrentContact.DeleteCustomerContactOnly(); to delete contact from the commerce db, but nothing seems to happen.

Is there something that I am missing regarding deleting users from commerce?


Rui Vaz

Edited, Nov 07, 2018 15:09

I would suggest to go with DeleteWithAllDependents. It only deletes contact-related information (billing address, etc.) It does not delete the orders associated 

Nov 07, 2018 15:32

That was the first one i tried. Nothing happened either :/ i suppose i am missing something. not sure what tho.

Nov 07, 2018 15:34

It does not delete the users, it deletes the current contact. If you go to this 

and the contact disappears then it worked

Nov 07, 2018 15:41


Yes i am aware. But contact doesn't disappear from that table :) Maybe I have to log out user after deleting? I know that a user is created in the commerce db upon first login. Maybe if he's still logged in after deletion he is recreated?

Edited, Nov 07, 2018 15:44

Do you have a feature that allows customers to delete their own contact information? 

It seems to me this is a cache problem. Does it disappear if you IIS reset? If you actually looked into db then ... is there anything in log?

Nov 07, 2018 15:50

Hi Quan.

Yes i am. Goal is to be in compliance with GDPR right to be forgotten. Do you suggest a different approach?

I can confirm that if i sign out user after deleting it from commerce, it is removed from the commerce db.

Nov 07, 2018 20:58
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.