Battling on with the Batch API

I have on several occasions expressed my delight about the arrival of the Batch API. I am still enthusiastic but somewhat war weary having spent this passed week trying to solve problems that have appeared. Clearly the Batch API was not rigorously tested before it was released as otherwise the sort of errors I am getting would not have appeared. In case you have been struggling too or in case you thinking about using this functionality here is what I have been up against.

Using the batch API consists of two parts; creating the batch and then populating the batch you have created. When you add records to a batch you load the CBatchAPI object either by name or id. You then use the child collection property of type CTemprecords in order to add a row to the batch. This is a similar concept to adding a notepad to a constituent:

Dim tempRecords as CTempRecords
Dim tempRecord as CTempRecord

tempRecords = batchAPI.tempRecords
tempRecord = tempRecords.Add

Now I have done this before and it has worked fine but when I tried it this time I got the error message (including the line spacing):
“Nothing:

Init method must be called before using this object”

This was very confusing. The only object that has an Init method is the CBatchAPI and I certainly did initialize that. Like many error messages this is a red herring and a symptom of an internal API problem. After two frustrating days I get the code to work. Initially I was testing the code on version 7.82 against a SQL Server 2005 database. Now testing it on 7.82 against a SQL Server 2000 database it works. This appears to work with the 7.85 and 2005 combination so should not cause too many problems to the majority of people but it is not a good sign.

And to the other issue. I wanted to add the letter code to my batch. I didn’t need to populate it just ensure that it was there.  I admit at this stage that I didn’t check the various alternatives that carefully. I thought that I should use the code: GIFT_fld_AckLetterActionID. Seemed reasonable enough. It was next to the acknowledgement date and whether or not the gift had been acknowledged. (for reference this was the wrong code. It should have been: GIFT_fld_Letter_Code).  Once I had created the batch, I proceed to populated it. I then saved the batch and got the following error:

Run-time exception thrown : System.Runtime.InteropServices.COMException – General ODBC Error: [Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near ‘,’.
Native error:170
[Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared.
Native error:8180

Once again this clearly shows an internal code problem. Now clearly I was using the wrong code in this case but the point is that a finished piece of software should not produce this kind of error message. It took me a while to hunt down the problem.

I stand by my claim that the Batch API is an extremely useful addition to the API tools available. However the fact that the procedures for setting up batches and getting data into the batches are not well defined and that there are a lot of erroneous errors appearing does not lend much confidence to the ability of the API to perform.

3 thoughts on “Battling on with the Batch API

  1. Hi David,

    I am working on something now whereby I am adding gifts to a batch. I am getting the same exact error you mentioned above: Init method must be called before using this object. I have worked on gift batches in the past as well successfully. Any suggestions on possible workarounds????

    Thanks

    Steve

  2. Steve,

    Rather than adding values to the gift that corresponds to the batch, you could try adding values to the batch directly. You will need to determine which field to add it to but this has worked in some cases where there have been issues.

    I have not had this particular error for a while now. I am not sure if that means it was fixed for the areas I was working on or have just not been doing the same type of batches.

  3. I’m getting the
    “Nothing:
    Init method must be called before using this object”
    at the moment when trying to update data in a batch. It works fine the first time, but after that it returns that error. The batch is still initialised.

    I’ve started a Case with BB, but if there’s no luck from that direction I’m going to have figure something else out, perhaps doing a closedown then init/load whenever I want to do something.

Comments are closed.