avoid "Cannot use SAVE TRANSACTION within a distributed transaction" error between SQL 2005 and 2008

StackOverflow https://stackoverflow.com/questions/16546849

Question

in our production environment we have a stored procedure (in sql 2005 server) that import data into a local table from a remote stored procedure (stored in a remote sql 2008).

The code is like this:

insert  <<local table name>> (fund, strat, clr, [id], position, unsettledPosition)
exec    <<remote stored proc name>> 'aapl us' , '2013-05-13'

I receive this error:

Cannot use SAVE TRANSACTION within a distributed transaction.

and

The current transaction cannot be committed and cannot support operations that write to the log file. Roll back the transaction.

I have configured both local and remote DTC allowing DTC Access over Network, Allowing Remote Clients option, also allowing Inbound & Outbound Communication, and finally enabling XA Transactions, but without any success.

Until yesterday the remote server was an old SQL 2005 and my code worked well, then I guess I miss some config settings in the new server 2008.

Please could someone help me?

Was it helpful?

Solution

This error is easily reproduced, with MSDTC turned on:

BEGIN DISTRIBUTED TRANSACTION;

...

SAVE TRANSACTION abc;

According to this link, the ability to use SAVEPOINTs in a Distributed transaction was dropped in SQL 7, i.e. not a breaking change in SQL 2008 (R2).

It is likely that you previously were NOT running under a Distributed Transaction, but now are, e.g. previously, the remote proc may have been on a different database on the same server, hence no need for a DTC transaction.

So unfortunately, it seems you need to either drop the bounding ACID transaction, or change the SPROC on the remote server so it doesn't use SAVEPOINTs.

Update As per the comments below, it appears that the REMOTE_PROC_TRANSACTIONS option had been set on the OP's newer SQL 2008 server, which automatically begins a distributed transaction across remote stored proc calls.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top