Search code examples
c#.nettransactionslinked-server

Distributed Transaction Error Only Through Code


I and trying to perform a query against a linked server (SQL Server 2008 linked to Sybase) and select it into a temp table. Is works perfectly though a query window in SQL Management Studio, but when I do it through code (C#) it fails with the error "The operation could not be performed because OLE DB provider "ASEOLEDB" for linked server "MYLINKEDSERVER" was unable to begin a distributed transaction. I am not using a transaction in code with my DbConnection.

This query looks like this:

SELECT * 
INTO #temptable
FROM OPENQUERY([MYLINKEDSERVER], 'SELECT * from table')

Solution

  • Found the issue. It was a result of connection pooling. It appears that connections were getting reused causing the system to think there was a distributed transaction happening.