web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Batch class does not enter insert method when setting recurrence

(0) ShareShare
ReportReport
Posted on by

I created a batch class for the data import from SQL and ran it. The class works correctly the first time it runs, but it doesn't update when I set recurrence and delete/add records. The code goes from 215 to 237 and from there to 243 and makes an insert, but when Recurrence works, it comes to 215 and goes from there to 237 and then to 238 and does not enter the insert. how can I figure this out?


Screenshot-2022_2D00_12_2D00_02-at-10.25.27-_2800_2_2900_.png

I have the same question (0)
  • Martin Dráb Profile Picture
    236,192 Most Valuable Professional on at
    RE: Batch class does not enter insert method when setting recurrence

    It seems that a CLR exception gets thrown at line 237, which you don't catch. That's why the next line isn't reached. The data is already committed at that point.

    I also see logical errors in your code. You dispose the reader at lines 205 and 220,  but you don't break the execution, therefore line 210 will try to call Read() on already disposed reader. I assume you actually meant throwing an error, not just adding a message to infolog. Therefore you should use throw error(...) instead of mere error(...). If you agree, then you don't need the catch block inside the loop. Also, your catch block can be greatly simplified and you can put the common logic to finally. For example:

    System.Exception ex;
    
    try
    {
    	while (reader.Read())
    	{
    		...
    	}
    }
    catch (ex)
    {
    	throw error(strFmt(..., ex.Message));
    }
    finally
    {
    	if (reader)
    	{
    		reader.Dispose();
    	}
    }

    If would have adjusted your code if you provided it as text and not as a screenshot.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,351

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 874 Super User 2025 Season 2

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 638 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans