Skip to Content
author's profile photo Former Member
Former Member

StartTransaction and EndTransaction

I need to import a XML file, with Journal Entries, several times in a month.

The file has about 100 Journal Entries and, for example, if the 80th, gives an error, after that, the process stops and has to "rollback" the others 79.

First of All, when importing I begin the transaction:



'After add the lines



'After fill the header, add the entry



The problem is that after we .Add(), it commits the transaction and we cannot rollback.

Could someone help how can I do that? Or How can we use the oCompany.StartTransaction()

Ribeiro Santos

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2005 at 07:34 AM


    Can you show us the line of code you're using when you try to rollback?

    I've been using the transaction feature a lot and I heven't had any problems yet (after I got it working). But I'm not using it on journal entries.

    Except that SBO will crash after there are several unfinished transactions (stopping debugger). Also nested transactiosn do not seem possible.



    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      Please note that you have to check every return value e.g. of transactions like "Add" - regardless whether or not you use global transactions / the StartTransaction-EndTransaction mechanism or not!

      The global transaction mode will be terminated whenever DI API encounters any error (exception or error indicated via return codes).

      All transactions performed afterwards are then single transactions - without further notice. Company object's "InTransaction" property indicates whether or not the global transaction is still open.

      If you try to call EndTransaction in such a situation, an exception will be thrown, telling you that the connection would not be in a (global) transaction.

      Please show us more code, if this does not help you.



      PS: SDK classroom training also covers such questions.

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2005 at 10:51 AM


    I found the problem:

    I just Call oCompany.StartTransaction once (at the begin of the process), after, when I get the first error, the transaction ends, and like I continues to Add Journal Entries, B1 "auto commit" these transactions.

    For each JournalEntries I have to StartTransaction, Add the JE, and then End the transaction.


    Ribeiro Santos

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Sorry, I forgot to say that, I have to "test" all the Journal Entries, to inform the user what are the errors.

      Them the user should correct them and then import again.

      That's why I have to pass twice. But, yes, if no errors found them is just one pass.

      Ribeiro Santos

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2005 at 02:21 PM


    below is an code sample that shows how you can handle global transactions with DI API:

    '//starts transaction - each failoure will cause rollback

    '// 'InTransaction' property will turn to TRUE


    For i = 0 To Count

    'Add Journal Entry


    TransID = CreateJournalEntry(i)

    '//In case of failure of a single transaction (e.g creation of the Journal Entry)

    '//the transaction will be rolled back automatically:

    '//1) all the former changes in the database will be canceled (delete all the journal entries 0...i-1)

    '//2) 'InTransaction' property will turn to FALSE

    If Not (oCompany.InTransaction) Then Exit For

    '//although the transaction was terminated the code will continue from the same location

    '//(journal entries i+1.....count will be created)

    '//it is the developer responsability to skip to the end of the transaction (in this example, 'Exit For')

    Next i

    If oCompany.InTransaction Then oCompany.EndTransaction wf_Commit

    '//'EndTransaction' method cannot be executed if the transaction is not active

    '//meaning if the transaction was rolled back automatically there is not need to end the transaction

    '//it can be check by checking the value of 'InTransaction' property

    as it can be understood from the sample, in case of an error within the transaction, the transaction will be terminated AUTOMATICALLY, the devloper is not expected to call 'EndTransaction' method with wf_RollBack as parameter

    the parameter wf_RollBack enable the user to rollback the whole transaction in case there was no error in a single transation, but from some other reason the transaction has to be cancelled anyway

    Regards, Avi.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.