473,386 Members | 1,710 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,386 software developers and data experts.

Triggers from one MSDE to another using DTC

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 source tables to update the target
tables using a linked servers setup. Distributed Transaction Coordinator is
running on both source and target servers.

This following create command:

CREATE TRIGGER JonsTrigger
ON associate
FOR INSERT
AS
INSERT into JON1.ISR_DB.dbo.associate
select * from inserted
GO
will generate the following error:

Server: Msg 7395, Level 16, State 2, Procedure JonsTrigger, Line 5
Unable to start a nested transaction for OLE DB provider 'SQLOLEDB'. A
nested transaction was required because the XACT_ABORT option was set to
OFF.
[OLE/DB provider returned message: Cannot start more transactions on this
session.]
OLE DB error trace [OLE/DB Provider 'SQLOLEDB'
ITransactionLocal::StartTransaction returned 0x8004d013: ISOLEVEL=4096].

OK fine, as the error says, use XACT_ABORT ON around the trigger INSERT and
all works well and the insert gets fired over to the target machine. I
believe we need this set as SQL doesnt support nested transactions ? Any way
, so far so good . In principle it will work......

The issue we have is that if the trigger fails ( target machine not
available etc etc ) the whole transaction is rolled back including the
originating transaction that the trigger was fired from. Problem is that we
dont want the original insert to fail. How can we isolate the two. Original
insert must occur no matter what. The trigger will do the best it can to
update the backup DB but we dont want the whole thing to fail if it cant.

I have looked around BEGIN DISTRIBUTED TRANSACTION and couldnt get it to
make a difference. Have looked at removing the XACT_ABORT but cant get the
update to succeed if this is missing. Have thought about using a stored
procedure in some way but not quite sure how !

Can anyone shed any light on this please.

Thanks

Jon
Jul 20 '05 #1
3 4395
"Jonathan Bishop" <Jo*************@BTInternet.com> wrote in message news:<ce**********@sparta.btinternet.com>...
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 source tables to update the target
tables using a linked servers setup. Distributed Transaction Coordinator is
running on both source and target servers.


<snip>

You might find the information here useful:

http://www.sommarskog.se/error-handling-I.html

Personally, I would avoid the trigger solution completely, and look at
an alternative approach. Specifically, log shipping and replication
are good ways to maintain an up to date copy of a production database
on a different server. Log shipping is only available in Enterprise
Edition, however implementing your own solution in MSDE should be
quite straightforward:

http://www.winnetmag.com/Article/Art...231/23231.html
http://sqlguy.home.comcast.net/logship.htm
http://www.sql-server-performance.co...g_shipping.asp

Or you could look at replication, which would replicate all
transactions from your source server to the target server. While log
shipping copies all changes, replication can copy changes made to
specific tables only. This is quite powerful, but it adds a certain
amount of complexity to your environment, which may or may not be a
good trade-off for you. See Books Online for more information, and
also this article:

http://support.microsoft.com/default...;en-us;Q324992

Simon
Jul 20 '05 #2
Jonathan Bishop (Jo*************@BTInternet.com) writes:
The issue we have is that if the trigger fails ( target machine not
available etc etc ) the whole transaction is rolled back including the
originating transaction that the trigger was fired from. Problem is that
we dont want the original insert to fail. How can we isolate the two.
Original insert must occur no matter what. The trigger will do the best
it can to update the backup DB but we dont want the whole thing to fail
if it cant.


If you want the insert to always succeed, you cannot perform the insert
on the remote table in the trigger. In SQL Server a DML statement -
INSERT, UPDATE or DELETE - is always atomic. That is, it is always all
or nothing - and that includes the trigger.

One solution would be to insert to a local table, and then have another
process to perform the replication. Simon suggested using replication
or log shipping, but this may a little heavy-duty. And I don't know
how much of that you can do in MSDE anyway.

OK, so there is a possible wya to use a trigger after all:

CREATE TRIGGER JonsTrigger
ON associate
FOR INSERT
AS
COMMIT TRANSACTION
INSERT into JON1.ISR_DB.dbo.associate
select * from inserted
BEGIN TRANSACTION
GO

But this would be very bad practice. And it would not work if the INSERT
statement is part of a multi-statement transaction. Also, if the INSERT
into the remote statement fails, the batch will still be terminated,
which means that any other statements in the batch are not run. The
closing BEGIN TRANSACTION is there, as else the batch would be terminated
because of the @@trancount in the trigger.

Again, I like to stress that this is a wretched solution, and I don't
know if Microsoft even considers it supported, and thus it could break
in the next version of SQL Server.
--
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 20 '05 #3
Thanks for the input gentlemen....

We are indeed looking at another solution ! We will probably settle on a
scheduled job to just update based on a status flag, rather than a trigger.
It should be about 10 mins up to date which is close enough.

Thanks again.

Jon.

"Jonathan Bishop" <Jo*************@BTInternet.com> wrote in message
news:ce**********@sparta.btinternet.com...
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 source tables to update the target tables using a linked servers setup. Distributed Transaction Coordinator is running on both source and target servers.

This following create command:

CREATE TRIGGER JonsTrigger
ON associate
FOR INSERT
AS
INSERT into JON1.ISR_DB.dbo.associate
select * from inserted
GO
will generate the following error:

Server: Msg 7395, Level 16, State 2, Procedure JonsTrigger, Line 5
Unable to start a nested transaction for OLE DB provider 'SQLOLEDB'. A
nested transaction was required because the XACT_ABORT option was set to
OFF.
[OLE/DB provider returned message: Cannot start more transactions on this
session.]
OLE DB error trace [OLE/DB Provider 'SQLOLEDB'
ITransactionLocal::StartTransaction returned 0x8004d013: ISOLEVEL=4096].

OK fine, as the error says, use XACT_ABORT ON around the trigger INSERT and all works well and the insert gets fired over to the target machine. I
believe we need this set as SQL doesnt support nested transactions ? Any way , so far so good . In principle it will work......

The issue we have is that if the trigger fails ( target machine not
available etc etc ) the whole transaction is rolled back including the
originating transaction that the trigger was fired from. Problem is that we dont want the original insert to fail. How can we isolate the two. Original insert must occur no matter what. The trigger will do the best it can to
update the backup DB but we dont want the whole thing to fail if it cant.

I have looked around BEGIN DISTRIBUTED TRANSACTION and couldnt get it to
make a difference. Have looked at removing the XACT_ABORT but cant get the
update to succeed if this is missing. Have thought about using a stored
procedure in some way but not quite sure how !

Can anyone shed any light on this please.

Thanks

Jon

Jul 20 '05 #4

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

Similar topics

5
by: Igor Solodovnikov | last post by:
Hi. I am trying to automatically backup transaction log when error 9002 happened. So i have created appropriate job and alert to catch this error. I have two instances of sql server under Windows...
10
by: noname | last post by:
MSDE 2000 Release A installed under windows 2000 pro will not communicate with SQL Server Manager nor MS Access on peer computer. Can someone help? Have set DISABLENETWORKPROTOCOLS=0 at install...
2
by: Rosy Moss | last post by:
I am in the process of cleaning up a database that our company uses to track jobs, time and expense, and customer information. We are running Windows 2000 Server with approximately 20 terminals...
41
by: NB | last post by:
Hi I have been developing on MS Access / Jet / VBA platform for about 2 years. The current project I am working on for a small business is built on Access 2002. It has about 53 tables in 2...
1
by: Paul Aspinall | last post by:
Hi I have a C# Winform app which runs using SQL Server. I want to package up the app, so that it deploys with MSDE. Can anyone offer any pointers or references to help?? Thanks
3
by: NWx | last post by:
Hi, I write an ASP,NET application who uses SQL Server (MSDE) as Back-end I'm an experienced developer, but haven't used SQL server before and I need some help. Since I don't have full SQL...
11
by: HC | last post by:
I posted this in one of the VB forums but I'm starting to think it might be more appropriate to have it here, since it really seems to be a SQL server (MSDE/Express 2005) problem: Hey, all, I...
9
by: HC | last post by:
Hello, all, I started out thinking my problems were elsewhere but as I have worked through this I have isolated my problem, currently, as a difference between MSDE and SQL Express 2005 (I'll just...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.