Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««123»»

Updating AS/400 Linked Server Tables from SQL Server Expand / Collapse
Author
Message
Posted Wednesday, August 23, 2006 10:48 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Thursday, August 14, 2014 12:14 PM
Points: 556, Visits: 1,082
I have found that either of the following methods work. The second is MUCH faster:
1.
UPDATE ISERIES.Serial#.Library.File
SET field1 = RTRIM(field1) + ' Changed' WHERE field2 = '00248000'

2.
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




Ken
Post #303580
Posted Thursday, April 5, 2007 6:58 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Wednesday, August 13, 2014 2:57 PM
Points: 61, Visits: 262

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

Post #356222
Posted Thursday, April 5, 2007 8:20 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Thursday, August 28, 2014 4:00 AM
Points: 21,397, Visits: 9,612
Sure can, the search engines don't care about the post date .
Post #356271
Posted Tuesday, April 10, 2007 2:33 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, January 9, 2013 5:52 AM
Points: 4, Visits: 10

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.

/PG

Post #357090
Posted Monday, April 23, 2007 9:37 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 23, 2007 9:10 AM
Points: 3, Visits: 1

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...

Post #360298
Posted Friday, July 6, 2007 7:32 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Wednesday, June 4, 2014 12:21 PM
Points: 1,327, Visits: 155

...anyway i got a trigger (insert) as i want to insert in as400 tables the same data ...

Joel;

DON'T!!!  Do not put code in a trigger that depends on an external resource!  I have seen this same example at a client, and they were complaining about how slow the database was (they were getting SQL query and web site timeouts).  Your communication to the external database will not be quick, and the user's update is held up waiting for the external DB2 update to work.  If the user's update is held up, then the db connection is held up, the table locking blocks other updates, the user's application is held up, and you end up with a slow system that cannot handle many concurrent updates.

If you were using SQL Server 2005, I would suggest using Broker Services and having the trigger to write an entry to a broker queue.  The queue would be setup with a stored proc to perform the DB2 update.  The difference would be that the broker queue would work asynchronously, the trigger would be done and the users' update would complete without waiting for the DB2 update.

With SQL Server 2000, you will have to do more work to implement an asynchronous solution.  If you have IIS available, you could write a web service that can be called asynchronously from the trigger.  But that solution does not provide much failover support.  Perhaps best would be to write out the update to another local table, then have a job runnning every minute to pickup updates from this table and update DB2.  Or you could have a flag or timestamp on updated record, that the job would look for and use for making the updates to DB2.

Hope this helps





Mark
Post #379572
Posted Friday, July 6, 2007 9:19 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, August 28, 2014 5:41 PM
Points: 61, Visits: 224
Yes, I´m working several U/I/D on as400 Tables using linked servers.

You only need to have an activated journal on the as400 table.

Maria Pia Fernandez
SQL Total Consulting



Post #379734
Posted Saturday, July 7, 2007 7:41 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 11, 2014 7:40 AM
Points: 3, Visits: 15
Marco, could you please provide an example of the commands you use with the STRJRNPF command?  We currently use DTS packages and are trying to eliminate them and execute everything from stored procedures.  Thanks!
Post #379771
Posted Friday, October 12, 2007 8:07 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Monday, April 6, 2009 2:41 PM
Points: 1, Visits: 20
Hi

I need to update AS400 Linked server tables as soon as a table on SQL server 2005 is updated. I have created a trigger for the same which is given below:

Create Trigger testTrigger
on testTable
For UPDATE
AS
DECLARE @count int;
Begin
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- select the rows from inserted table
select @count=count(*) from testTable t inner join inserted i on t.id = i.id
if @count > 0
Update LinkedAS400.xyz.abc.as400testtable set var1 = ('X') Where var2=1

End
Go

The update query works fine when executed separately, but from a trigger, it returns with the following error
"Msg 7390, Level 16, State 2, Procedure testTrigger
The requested operation could not be performed because OLE DB provider "IBMDA400" for linked server "LinkedAS400" does not support the required transaction interface."

The MSDTC service is started and the journals have also been turned on on the AS400 side.
What else am I missing here?


Post #409993
Posted Saturday, October 13, 2007 5:03 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, June 11, 2014 7:40 AM
Points: 3, Visits: 15
As Rafael stated:

rafael lenartowicz (4/5/2007)

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'' ')

:: ::


In other words, AS400 is a SQL object, not an AS400/DB2 object.

If you are updating large amounts of data, you may want to use a DTS package or VBScript to call a procedure on the AS400. One test analysis I conducted, deletes always took around 50 minutes to complete; the inserts 6 to 10 minutes. This was with only 85,000 records where a DTS call would take seconds or less.

Note, too, that if your trigger is using variables to create the statement you will need to encapsulate them in a variant string and execute them that way. OpenQuery does not accept variables. I've also never needed to use the parentheses around the update value.

See some other info on this subject at http://sqlforums.windowsitpro.com/web/forum/messageview.aspx?catid=65&threadid=47240&STARTPAGE=1

My unrelated 2¢ worth: select(1) is more efficient than select(*).
Post #410281
« Prev Topic | Next Topic »

Add to briefcase ««123»»

Permissions Expand / Collapse