Updating AS/400 Linked Server Tables from SQL Server

  • Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/bHullur/updatingas400linkedservertablesfromsqlserver.asp

  • I am using Linked Server to update AS/400 tables since a lot.

    The only problem I found is that the Table on AS/400 has to be "journaled".

    You can achieve this with the STRJRNPF command onto the AS/400



  • Marco - What do you mean by "Journaled"



  • Hi Martin:

    In the scenario described in the article, journaling was not turned on. The AS400 person did not want to turn it on for some reason and I had to work within that constraint. I did read about it and tried my best to get it turned on.



  • Hi.

    I use Microsoft OLE DB Provider for DB2  (DB2OLEDB) for linking to AS/400 from SQL-Server 2000

    I use OpenQuery for all reading (best performance)

    Have no problem with updating the way described in the article, exept for performance on large tables.

    Anyone know how to process a pass-through update query ?

    That should be fast even in large/huge tables !


  • Journaling is how the AS/400 tracks activity against a table.  The journal then can be used in recovering a table by either applying activities or removing them.  If a table is not journaled, then you only have the backups to recover from.  I guess you could compare this to Simple versus Full recovery mode on SQL Server.

    It's been a while since I've worked on the AS/400 so IBM may have changed how this works.


  • Journaling is required for a table to be updated/deleted in AS400.  Effectively if journaling is off for the table it is read-only through DB2. 

    One other problem I've run across when updating to the AS400 had to do with the setup of the ODBC driver itself.  For the iSeries ODBC driver verision there are settings that can cause diffculty and seem to work for updating or selection, but not both.  In the Performance tab, under the Advanced button, these are the settings:

    Open All Cursors as updateable --Set ON for update, Off for select

    Retrieve extended column information --set ON for update, Off for select

    I've had to set up 2 different datasources, one for read, and another for write.  If anyone else has run into this and solved it, or if there's a version up that's fixed this I'd love to know.

    -Larry Smith

  • where it is true that Journaling needs to be enabled on the table for it to be updated, it is not correct to say that table is read-only.

    I have the very same issue with as400 and after some searching had made several discoveries.

    1. You can update the table in as400 even if Journaling is not turn on , but ony if you are sing ADO recordset object.

    I do not remember the settings that need to configured for it to work , but I know it's possible.

    2. the reason you have an issues with updating table in t-SQL is becouse of the SQL server ways of executing the queries.

    SQL server when executing queries against linked tables and/or ODBC connected tables in as400 DB require the query to be logged and commited in specific way, and it's requires a proper response from query engine , the as400 engine dose not send the proper response back if the table is not Journaled, thus making the SQL server think that query is not successfull becouse the talbe is read-only.

    I have found no other way to make this work but to enable Journaling on the table.

  • We are using Linked Server to update AS/400 tables since a lot. We have "Jornaling" for all updateble AS/400 tables

    The only problem we found is to implement DISTRIBUTED TRANSACTION between SQL Server 2000/2005  and AS/400. If anyone else has run into this and solved it ?


  • Hi.

    I have problem when updating large tables (> million rows) using traditional

    4 level naming in update like:


    SET ZZSSRV = '2006-02-08 09:00:19'

    It works but is very slow.

    It seems like all data first is retrieved to SQL-Server, updated at SQL-Server and then finally sent back to the AS/400 and comitted.

    Do any one know a working pass-through-method for updating ?

    I've tried using openquery like:

    Select * from OPENQUERY(AS400, '


    SET ZZSSRV = ''2006-02-08 09:00:19'' ')

    It does not work.

    Any suggestions ?

  • I have found that either of the following methods work. The second is MUCH faster:


    UPDATE ISERIES.Serial#.Library.File

    SET field1 = RTRIM(field1) + ' Changed' WHERE field2 = '00248000'


    UPDATE OPENQUERY(ISERIES, 'SELECT * FROM Library.File WHERE field2 = ''00248000'' ')

    SET field1 = RTRIM(field1) + ' Changed' WHERE field2 = '00248000'

    The last WHERE clause is probably unnecessary since it is included in the OPENQUERY SELECT


  • if you're using OPENQUERY you are executing the SQL "inside" of the AS/400. AS400.S1019865.NSCDEVDATA.WSZZP100 doesn't exist in the AS/400 world. Try this :

    Select * from OPENQUERY(AS400, 'UPDATE  NSCDEVDATA/WSZZP100 SET ZZSSRV = ''2006-02-08 09:00:19'' ')

    ooops... I just realized this message was posted 1+ year ago

    oh well, maybe somebody else can still use it now

  • Sure can, the search engines don't care about the post date .

  • I found a good and fast solution for updating linked AS/400

    It is the same solution that Ken LaRoy suggest

    UPDATE OPENQUERY(ISERIES, 'SELECT * FROM Library.File WHERE field2 = ''00248000'' ')

    SET field1 = RTRIM(field1) + ' Changed'  -- WHERE field2 = '00248000'

    The last WHERE clause is unnecessary since it is included in the OPENQUERY SELECT

    Very fast, even though the AS/400-table has million of rows.


  • i have set a linked server in sql 200 sp4 to as4000 with the provider for db2 (host integration 2006)

    im able to see the tables and all basic query's worked fine (i imported all the as400 tables i want with the same name in both servers)

    anyway i got a trigger (insert) as i want to insert in as400 tables the same data that i insert in sql table (i could call it replication) but it gives me this error when i type a insert in the sql table.

    Server: Msg 7391, Level 16, State 1, Procedure INSERT_WMCS01F, Line 18

    The operation could not be performed because the OLE DB provider 'DB2OLEDB' was unable to begin a distributed transaction.

    OLE DB error trace [OLE/DB Provider 'DB2OLEDB'' ITransactionJoin::JoinTransaction returned 0x8004d00a].

    I would appreciate if you could help me...

    PD: MSTDC is active and i configured after have read some things in msdn website, i disabled also the connection pooling as says in another msdn article, and made many other things i still have this problem and dont know whtat is missing to work fine...

Viewing 15 posts - 1 through 15 (of 24 total)

You must be logged in to reply to this topic. Login to reply