Question

My problem is very simple yet I searched high and low but only to find vague and non working solutions.

I am using Talend Data Integration . I have a very simple job set up where it imports a set of rows from an Excel file into a Microsoft SQL database.

My problem is after inserting these new rows, I need to further work with them and I need to know their primary keys as they were generated by the database upon insert.

I have tried the tMSSqlLastInsertId component but that always returns zero. I have tried re-selecting from the database but inexplicably the primary keys are also zero. Even though I have checked to be sure that in the database the entries do have correct primary keys set.

Was it helpful?

Solution

Weird and apparently inexplicable problem. Perhaps a commit/lock issue?

My advice is to reselect the rows in a different subjob, to force a commit after the tMsqlOutput component. Ofc you need to use a differente connection to DB for the subsequent input stage, to be sure the commit in the output stage was well done. And be careful checking the schema (number, type, order of columns: you would have one more - the auto key) in the Input stage. Something like:

[starting component of the subjob]--->row---->[...]-->row--->tMSSqlOutput
         |
         |
    OnSubjobOk
         |
         |
        \ /
         '
     tMSSInput---row--->[...]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top