473,413 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Problem with triggers between linked servers

I have two SQL Server 2000 machines (server_A and server_B). I've
used sp_addlinkedserver to link them both, the link seems to behave
fine. I can execute remote queries and do all types of neat things
from one while logged onto the other.

I'm working on a project to keep the data in the two systems
synchronized, so I'm using triggers on both sides to update each
other. For testing, I've created a simple, one-column table on both
servers, and also created a trigger on both tables. Consider the
following trigger code on server_A:

CREATE TRIGGER myTrigger
ON myTable
FOR INSERT
AS
SET XACT_ABORT ON
SET NOCOUNT ON
INSERT INTO server_B.myDB.dbo.myTable SELECT * FROM inserted
GO

And also the following trigger code on server_B:

CREATE TRIGGER myTrigger
ON myTable
FOR INSERT
AS
SET XACT_ABORT ON
SET NOCOUNT ON
INSERT INTO server_A.myDB.dbo.myTable SELECT * FROM inserted
GO

Before you start screaming about the recursive relationship between
these triggers, I'm well aware of that issue, so I'm wrapping the
trigger logic with a login ID test. The servers are linked using a
special login account, I'll call it 'trigger_bypass_login', so the
triggers look like this:

CREATE TRIGGER myTrigger
ON myTable
FOR INSERT
AS
SET XACT_ABORT ON
SET NOCOUNT ON
IF SUSER_SNAME() <> 'trigger_bypass_login'
INSERT INTO server_A.myDB.dbo.myTable SELECT * FROM inserted
GO

Although this logically works fine, there seems to be a compile issue,
because I'm running into the error:

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

What is strange is that I CONTINUE TO GET THE ERROR if I change the
trigger code to the following:

CREATE TRIGGER myTrigger
ON myTable
FOR INSERT
AS
SET XACT_ABORT ON
SET NOCOUNT ON
IF 1=0
INSERT INTO server_A.myDB.dbo.myTable SELECT * FROM inserted
GO

So obviously, it has nothing to do with the actual inserting that the
INSERT performs, but rather the fact that the trigger INSERT
references the linked server/table.

So, I moved the INSERT statement to a stored procedure, and it works
and I no longer get the error:

CREATE TRIGGER myTrigger
ON myTable
FOR INSERT
AS
SET XACT_ABORT ON
SET NOCOUNT ON
IF SUSER_SNAME() <> 'trigger_bypass_login'
EXEC myStoredProcedure
GO

It works.. BUT, the stored procedure does not have access to the SQL
Server 'inserted' trigger table. I've tried using

DECLARE CURSOR myCursor GLOBAL FOR SELECT * FROM inserted

and then letting the stored procedure reference the cursor, but then I
have to deal with the cursor data on a column-level basis, which is
not an option in this project because there are 100's of tables with
many columns, which might change over time.

So it is of extreme importance that I use INSERT INTO ... SELECT to
move the row data in a generic fashion.

I hope I have provided enough, yet not too much, information.

I would really appreciate any suggestions anyone might have as to how
I might handle this situation. Thanks.

Hank
Jul 20 '05 #1
4 14200
ha*********@yahoo.com (Hank) wrote in message news:<39**************************@posting.google. com>...
I have two SQL Server 2000 machines (server_A and server_B). I've
used sp_addlinkedserver to link them both, the link seems to behave
fine. I can execute remote queries and do all types of neat things
from one while logged onto the other.

I'm working on a project to keep the data in the two systems
synchronized, so I'm using triggers on both sides to update each
other. For testing, I've created a simple, one-column table on both
servers, and also created a trigger on both tables. Consider the
following trigger code on server_A:

CREATE TRIGGER myTrigger
ON myTable
FOR INSERT
AS
SET XACT_ABORT ON
SET NOCOUNT ON
INSERT INTO server_B.myDB.dbo.myTable SELECT * FROM inserted
GO

And also the following trigger code on server_B:

CREATE TRIGGER myTrigger
ON myTable
FOR INSERT
AS
SET XACT_ABORT ON
SET NOCOUNT ON
INSERT INTO server_A.myDB.dbo.myTable SELECT * FROM inserted
GO

Before you start screaming about the recursive relationship between
these triggers, I'm well aware of that issue, so I'm wrapping the
trigger logic with a login ID test. The servers are linked using a
special login account, I'll call it 'trigger_bypass_login', so the
triggers look like this:

CREATE TRIGGER myTrigger
ON myTable
FOR INSERT
AS
SET XACT_ABORT ON
SET NOCOUNT ON
IF SUSER_SNAME() <> 'trigger_bypass_login'
INSERT INTO server_A.myDB.dbo.myTable SELECT * FROM inserted
GO

Although this logically works fine, there seems to be a compile issue,
because I'm running into the error:

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

What is strange is that I CONTINUE TO GET THE ERROR if I change the
trigger code to the following:

CREATE TRIGGER myTrigger
ON myTable
FOR INSERT
AS
SET XACT_ABORT ON
SET NOCOUNT ON
IF 1=0
INSERT INTO server_A.myDB.dbo.myTable SELECT * FROM inserted
GO

So obviously, it has nothing to do with the actual inserting that the
INSERT performs, but rather the fact that the trigger INSERT
references the linked server/table.

So, I moved the INSERT statement to a stored procedure, and it works
and I no longer get the error:

CREATE TRIGGER myTrigger
ON myTable
FOR INSERT
AS
SET XACT_ABORT ON
SET NOCOUNT ON
IF SUSER_SNAME() <> 'trigger_bypass_login'
EXEC myStoredProcedure
GO

It works.. BUT, the stored procedure does not have access to the SQL
Server 'inserted' trigger table. I've tried using

DECLARE CURSOR myCursor GLOBAL FOR SELECT * FROM inserted

and then letting the stored procedure reference the cursor, but then I
have to deal with the cursor data on a column-level basis, which is
not an option in this project because there are 100's of tables with
many columns, which might change over time.

So it is of extreme importance that I use INSERT INTO ... SELECT to
move the row data in a generic fashion.

I hope I have provided enough, yet not too much, information.

I would really appreciate any suggestions anyone might have as to how
I might handle this situation. Thanks.

Hank


Check this KB article, which gives a lot of detail on troubleshooting
that error. The most common issues seem to be that MSDTC isn't
running, or that there is a firewall between the servers.

http://support.microsoft.com/default...&Product=sql2k

Simon
Jul 20 '05 #2
sq*@hayes.ch (Simon Hayes) wrote in message news:<60**************************@posting.google. com>...

Check this KB article, which gives a lot of detail on troubleshooting
that error. The most common issues seem to be that MSDTC isn't
running, or that there is a firewall between the servers.

http://support.microsoft.com/default...&Product=sql2k

Simon

Thanks for your input Simon.

MSDTC does not appear to be a problem. It is running on both
machines, and I can perform distributed transactions with no problem.
I can insert/update/delete linked server tables using four-part names
with no problem. Even the triggers between linked servers work fine,
as long as there are no recursive references in the trigger code,
regardless of whether the statement that causes the recursion gets
executed.

I also checked the troubleshooting link you sent.
- pingtest.bat runs fine on both machines
- both machines are using TCP/IP only
- transactions are not timing out because I can modify data using DTC
and linked servers with no problem when I'm not using triggers that
contain recursive references

The point in my original post that brought me here is the fact that I
get the error even if the recursive statement (the INSERT) doesn't get
executed. I thought this wouldn't be a problem, seeing as SQL Server
supports a server setting for 'nested triggers' which I've set to 1 on
both machines (and RECONFIGURE'd).

I first need to determine if what I'm doing is even supported. I've
searched BOL fairly extensively and all indications are that there
should be no problem. Additionally, I was hoping someone might
understand how SQL Server is compiling/executing this logic at the low
level, to better understand why the server, when executing a trigger,
even bothers looking at statements that don't get executed (i.e. the
false conditions of IF blocks).

Thanks again,
-Hank
Jul 20 '05 #3
I am having the SAME EXACT PROBLEM. Just implemented a new SQL FARM
and moved the databases over. Unable to perform an insert on linked
database...actually the fact that the statement is in the trigger and
not even called causes the error.

Did you ever get an answer/discover a resolution?
Your help in this matter would be greatly appreciated!

Thanks,
Reena

Jul 23 '05 #4
[posted and mailed, please reply in news]

(re***@cottermangroup.net) writes:
I am having the SAME EXACT PROBLEM. Just implemented a new SQL FARM
and moved the databases over. Unable to perform an insert on linked
database...actually the fact that the statement is in the trigger and
not even called causes the error.

Did you ever get an answer/discover a resolution?
Your help in this matter would be greatly appreciated!


In the thread there was a link to
http://support.microsoft.com/default...&Product=sql2k
Did you check whether there was anything that applies to you?

Else, it would helpful, if you gave the complete scenario with triggers
and statements. Preferrably simplified with only some few columns in
the table, but enough so anyone can run the example.

I reviewed the posting you refer to, but it wasn't clear to me how
his initial statement looked like, or at which point he got the error.
And in any case, your triggers may not look like his.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Raghuraman | last post by:
Hi, I was thinking abt linked servers deals only with multiple servers physically inter-connected. Now i come accross that we can link our non-sqlserver databases also. It is thru the...
3
by: Jonathan Bishop | last post by:
Hi. We are using MSDE2000 on a Point of Sale application. We need to keep a copy of a few key tables as up to date as possible for backup purposes. We are looking at using triggers over the...
1
by: TBlair | last post by:
I am about to start working on a project where I would be required to dynamically create linked servers during the execution of an application. One of the requirements is for the Link Servers to be...
5
by: yawnmoth | last post by:
say i have a form where, if a user clicks in it, all the text is highlighted, and where, if a user clicks on a button outside of the form, a certain text string is inserted where the cursor in the...
8
by: Bri | last post by:
Greetings, I'm having a very strange problem in an AC97 MDB with ODBC Linked tables to SQL Server 7. The table has an Identity field and a Timestamp field. The problem is that when a new record...
3
by: RandyMartin | last post by:
<<cross posted from microsoft.public.sqlserver.server>> Environment: Windows 2003 Standard Edition SP1, SQL 2005 EE RTM (both servers) I am getting the following messages when I run this...
9
by: dotnetfellow | last post by:
The system has worked for two years. SQL Server 2000 runs on Windows 2000 Server "A". Another instance of SQL Server 2000 was moved from Windows 2000 Server "B" old to Windows 2003 Server "B"...
2
by: =?utf-8?B?UMSBdmVscyBNaWhhaWxvdnM=?= | last post by:
Hello, I have a problem. I've linked MySql server to MsSql, in MySql I have a table with Latvian data(character set is ucs2, ucs2_general_ci) and the problem is that when I use openquery to read...
4
by: --CELKO-- | last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any kind of tools for this?
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.