Tell me more ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I'm using linked servers to perform some queries in a distributed transaction. It doesn't work in a distributed transaction. I get the following error:

Transaction context in use by another session.

Not even this simplified example will work:

IF EXISTS(SELECT server_id from sys.servers WHERE name = 'SomeServer')
BEGIN
       EXEC sp_dropserver  @server = N'SomeServer';
END

EXEC sp_addlinkedserver 
   @server = N'SomeServer',
   @srvproduct = N'',
   @provider = N'SQLNCLI',
   @datasrc = N'localhost';

EXEC sp_serveroption
       @server = N'SomeServer', 
       @optname = 'rpc out',
       @optvalue = 'on';
GO


BEGIN DISTRIBUTED TRAN;

EXEC('SELECT TOP 100 * FROM [SomeServer].[SomeDatabase].dbo.tblFoo')

ROLLBACK;

EXEC sp_dropserver  @server = N'SomeServer';

Removing the work distributed, or removing the begin/rollback tran entirely also works. Running sp_whoisactive returns no rows. I have had to restart the server (on my laptop) several times because there were distributed transactions I was unable to kill even if I killed all the spids returned by sp_whoisactive.

In those possible related instances, killing thos spids more then once gives me:

SPID X: transaction rollback in progress. Estimated rollback completion: 0%.

share|improve this question
1  
Have you tried using OPENQUERY() instead? msdn.microsoft.com/en-us/library/ms188427.aspx – OliverAsmus Apr 4 '12 at 12:50
I assume you have seen support.microsoft.com/kb/947486? – Chris Shain Apr 4 '12 at 15:56
1  
Likewise msdn.microsoft.com/en-us/library/ms188716.aspx. Have you tried disabling MARS on your linked connection? See msdn.microsoft.com/en-us/library/ee376925(v=sql.90).aspx – Chris Shain Apr 4 '12 at 15:58
1  
@ChrisShain so at this point the issue seems to be a combination of the loopback issue someone pointed out to me on twitter, plus the need to reboot after enabling network DTC calls when I tried to test for loopback issues. – Justin Dearing Apr 4 '12 at 17:36

1 Answer

what are you trying to do? for most simple data retrievals from linked servers you don't need to start a distributed tran. it shouldn't effect your ability to roolback a tran if that's what you're worried about. so just say "BEGIN TRANSACTION"

share|improve this answer
I will need a distributed transaction here because I will be modifying tables on both the local server and the linked server. – Justin Dearing Apr 4 '12 at 15:47
hmm, that's too bad. I always try to avoid DTC because it is so finicky and sometimes buggy. there are many attractive alternatives including CLR and service broker. – Mor Deror Apr 4 '12 at 19:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.