472,133 Members | 1,217 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

linked server referred by insert trigger

Hei,
We have 2 MS SQL SERVER 2000 installed on 2 different servers (2 separated
machines).
I am triing to connect them så that when one row is added to the table in
the database in main server - then the same row is added to the same table
in the second server database.
I made the insert trigger on the table in the first server ( the second
server is added as a linked server):
----------------------------------------------------------------------------
-------------
create trigger ti_myTabe1 on myTable1 for insert as
begin
declare ........
BEGIN
insert into server2.myDatabase2.owner.myTable2
(column1, column2, column3)
SELECT column1, column2, column3
FROM inserted ins
END
......
end
----------------------------------------------------------------------------
-------------

When I run the statement in "SQL Query Analyzer"on the first server:
insert into Table1 values(va1,val2,val3)
then error is coming:

Server: Msg 7391, Level 16, State 1, Procedure ti_myTabe1 , Line 19
The operation could not be performed because the OLE DB provider 'SQLOLEDB'
was unable to begin a distributed transaction.
[OLE/DB provider returned message: New transaction cannot enlist in the
specified transaction coordinator. ]
OLE DB error trace [OLE/DB Provider 'SQLOLEDB'
ITransactionJoin::JoinTransaction returned 0x8004d00a].

The straing thing is: if I run the statement in "SQL Query Analyzer"on the
first server:

insert into server2.myDatabase2.owner.myTable2 values(va1,val2,val3)

then it works!
But not inside the trigger!!! - What I am doing wrong ?

Any idea is greatly appeciated.


Jul 23 '05 #1
2 11592
There is a KB article here:

http://support.microsoft.com/kb/306212

And also a number of newsgroup discussions:

http://groups.google.co.uk/groups?q=...al&sa=N&tab=wg

The trigger requires a distributed transaction because it needs to be
in the same transaction as the statement that fired it, but a single
INSERT stands
alone, as it were. So if distributed transactions aren't working for
any of the reasons described in the KB article, then your trigger won't
either.

If you need to copy a lot of data from one server to another, you might
want to look into replication, although that might be overkill for what
you're doing.

Simon

Jul 23 '05 #2
Hi,

Your
insert into Table1 values(va1,val2,val3)
leads to a single transaction on two servers, because the insert in
table1 and the triggerd insert in server2.myDatabase2.owner.myTable2
by definition (of a trigger) are a single transaction. This is called
a distributed transaction. To be able to run distributed transactions
you should run the DTC service on both servers.

good luck,
Paul
"Elvira Zeinalova" <el**************@sff.no> wrote in message news:<1l*******************@news4.e.nsc.no>...
Hei,
We have 2 MS SQL SERVER 2000 installed on 2 different servers (2 separated
machines).
I am triing to connect them så that when one row is added to the table in
the database in main server - then the same row is added to the same table
in the second server database.
I made the insert trigger on the table in the first server ( the second
server is added as a linked server):
----------------------------------------------------------------------------
-------------
create trigger ti_myTabe1 on myTable1 for insert as
begin
declare ........
BEGIN
insert into server2.myDatabase2.owner.myTable2
(column1, column2, column3)
SELECT column1, column2, column3
FROM inserted ins
END
.....
end
----------------------------------------------------------------------------
-------------

When I run the statement in "SQL Query Analyzer"on the first server:
insert into Table1 values(va1,val2,val3)
then error is coming:

Server: Msg 7391, Level 16, State 1, Procedure ti_myTabe1 , Line 19
The operation could not be performed because the OLE DB provider 'SQLOLEDB'
was unable to begin a distributed transaction.
[OLE/DB provider returned message: New transaction cannot enlist in the
specified transaction coordinator. ]
OLE DB error trace [OLE/DB Provider 'SQLOLEDB'
ITransactionJoin::JoinTransaction returned 0x8004d00a].

The straing thing is: if I run the statement in "SQL Query Analyzer"on the
first server:

insert into server2.myDatabase2.owner.myTable2 values(va1,val2,val3)

then it works!
But not inside the trigger!!! - What I am doing wrong ?

Any idea is greatly appeciated.

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by kevin jin | last post: by
2 posts views Thread by Brian Salentine | last post: by
2 posts views Thread by Steve Kuekes | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.