Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 22nd, 2005, 07:05 AM
Authorized User
 
Join Date: Jun 2003
Posts: 95
Thanks: 0
Thanked 0 Times in 0 Posts
Default Linked Servers and Transactions

Hi, and thx in advance for any help.

Here is my problem:

I have a SP that is supposed to move data from one table in one DB to a table in another DB (see code below). Previously this has worked just fine. The databases was placed on two different physical servers. Then we needed to move the destination database to another physical server, and after that the SP will not do what it is supposed to (it says Running, but nothing happens). If I kill the process, it changes to KILLED/ROLLBACK, but it stays like that until we restart the server. If I remove the transaction handling from the SP, it works fine (but I really need the transaction handling).

The code is like this:
Code:
CREATE procedure PROC_Exportsettlementtoaxapta
AS
BEGIN

SET XACT_ABORT ON

IF @@TRANCOUNT<>0 ROLLBACK --Check for orphaned trans and rollback

DECLARE @errorcode int
set @errorcode=0

BEGIN TRAN 
--Transfer the values
insert into Lnk_INDIA.[Axapta].[dbo].[BE_FORBRUKMVDB]([ANLEGGSID], [VOLUM], [DATOFRA], [DATOTIL], [NYKID], [UKE], [CMX_DATOIMPORTERT], [AAR], [DATAAREAID], [IMPORTERT]) 
SELECT [Anleggsid],[Volum], [FraDato], [TilDato], [Axaptakid], [Uke],  [CMX_DatoImportert], [Aar],[DataAereaId], [Importert] FROM [AxaptaAvregning] where status=0

SET @errorcode=@@ERROR  --check for errors
IF @errorcode<>0 BEGIN
    RAISERROR('Error. Rolling back..',16,10)
    IF @@TRANCOUNT<>0 ROLLBACK

    SET XACT_ABORT OFF
    RETURN(@errorcode)
END

--If everything OK, update status
Update AxaptaAvregning set status=1 where status=0 
SET @errorcode=@@ERROR
IF @errorcode<>0 BEGIN
    RAISERROR('Error. Rolling back..',16,10)
    IF @@TRANCOUNT<>0 ROLLBACK

    SET XACT_ABORT OFF
    RETURN(@errorcode)
END


COMMIT TRAN

SET XACT_ABORT OFF

END
As mentioned before, if I remove the transaction handling, it works fine:

Code:
CREATE procedure PROC_Exportsettlementtoaxapta
AS
BEGIN


--Overfør verdier
insert into Lnk_INDIA.[Axapta].[dbo].[BE_FORBRUKMVDB]([ANLEGGSID], [VOLUM], [DATOFRA], [DATOTIL], [NYKID], [UKE], [CMX_DATOIMPORTERT], [AAR], [DATAAREAID], [IMPORTERT]) 
SELECT [Anleggsid],[Volum], [FraDato], [TilDato], [Axaptakid], [Uke],  [CMX_DatoImportert], [Aar],[DataAereaId], [Importert] FROM [AxaptaAvregning] where status=0


--Oppdater status
Update AxaptaAvregning set status=1 where status=0 


END
I have not found any different settings between the old physical server and the new one. Nor have I found any differences in the settings of the Linked servers.

Any suggestions welcome.

Best regards
Gert

 
Old April 27th, 2005, 02:56 AM
DMK DMK is offline
Registered User
 
Join Date: Apr 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Gert ,

        Start an explicit distributed transaction using the BEGIN DISTRIBUTED TRANSACTION statement.

Regards

DMK







Similar Threads
Thread Thread Starter Forum Replies Last Post
Linked Servers anothervbaddict SQL Server 2000 5 November 30th, 2007 07:31 AM
LINKED Servers. WebLadyBug SQL Server 2005 1 April 9th, 2007 01:27 AM
Linked Servers msrnivas .NET Web Services 1 January 8th, 2005 09:27 AM
linked servers msrnivas General .NET 1 November 26th, 2004 01:19 AM
linked servers bukky Classic ASP Databases 1 March 6th, 2004 06:31 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.