By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,267 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,267 IT Pros & Developers. It's quick & easy.

linked server referred by insert trigger

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.