Deleting 1000 records from entity

Hi,

I was trying to delete all the records(1000 records) from entity, Actually, On click of button, I called one screen action where the logic for deleting all the records is present. 

But When I clicked the button, It is throwing an exception saying that, "An exception occurred, A connection to the server is lost"..


Regards,

Sowndharya

Hello Divya, 

I am assuming you are executing an SQL statement at the screen action: DELETE FROM {your entity} ;

This would be the best way to delete all the records on an action, as it is a bulk change. 

Trying to use logic with aggregate + the DeleteYouEntity entity action is much less efficient and can cause problems. 

Of course, can be a different problem. 

So, if you place a breakpoint in the start of the screen action, the break point is reached? 

Are you generating an infinite looping? 

Is the database that stop responding? 

Too many cascade deletes? 

Cheers. 

Hi Sowndharya, Divya,

Deleting 1000s of records just from one entity is definitely not an expensive query unless there are references in other entities and you are performing cascade delete.

The error message " A connection to the server is lost", looks more of network issue, instead of entity problem. Can you reach the database in a normal situation and happens to get the issue when trying to perform this DELETE operation?

Regards,

Swatantra 

Solution

Hi divya v,

Let me reinforce what Eduardo mentions, hopefully in a more direct and clear way:

  1. The "An exception occurred, A connection to the server is lost" error message seems to hint that your screen action is taking too long to process;
  2. This may be due to several different reasons, but since you mention "the logic to delete the records" I'm guessing you are deleting your records one by one, using something similar to:
    • An aggregate to fetch the records you want to delete;
    • Followed by a For Each cycle to iterate through the resulting list and;
    • You are using the DeleteEntity entity action on each of the records.
  3. This means you're doing 1001 requests to the database to delete your records (1 to read the list, 1000 to delete each individual record - assuming you have 1000 records in your entity).

If this is the case, Eduardo's suggestion to simply replace your "logic to delete the records" with a single SQL statement with DELETE FROM {Entity} would be the most effective - it would correspond to one request to the database.

If this is not the case, please clarify how you are trying to delete all your entity records (maybe a screenshot of the screen action with the logic to delete the records?)

Solution

# just in case you really need time, execute job on that action.