Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 MSDTC with Dynamic SQL

Author  Topic 

dshelton
Yak Posting Veteran

73 Posts

Posted - 2007-07-03 : 20:53:10
Hi All,

I have come across an issue using distributed transactions with Dynamic SQL. The dist. transaction works fine when I insert using a standard insert proc but when I use exec('') this fails. I was hoping someone may know why this is happening.
Script:

DECLARE @exec VARCHAR(500)

SELECT @exec = (SELECT col1, col2 FROM linkedserver.database.dbo.table)

CREATE TABLE #table
(col1 int,
col2 int)

-- this insert runs
INSERT INTO #table
SELECT col1, col2 FROM linkedserver.database.dbo.table

-- this also runs
EXEC(@exec)

-- this fails
INSERT INTO #table
EXEC(@exec)

/*
This runs for about 3 minutes then I get the following error:
[OLE/DB provider returned message: New transaction cannot enlist in the specified transaction coordinator. ]
OLE DB error trace [OLE/DB Provider 'SQLOLEDB' ITransactionJoin::JoinTransaction returned 0x8004d00a].
Msg 7391, Level 16, State 1, Line 1
The operation could not be performed because the OLE DB provider 'SQLOLEDB' was unable to begin a distributed transaction.
*/


Thanks,
David

dshelton
Yak Posting Veteran

73 Posts

Posted - 2007-07-03 : 21:52:04
Further information on this, both servers are running Windows 2003 SP2. But the SQL version number is different, one server is 2039 and the is other is 2187.
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-07-04 : 00:27:00
Is msdtc running on both servers? What's os version?
Go to Top of Page

dshelton
Yak Posting Veteran

73 Posts

Posted - 2007-07-04 : 00:57:24
Yes, MSDTC is running on both servers with Windows 2003 Standard SP2 on both of these. I have also tried the same script between two sql servers with version 2039 and it seems to work fine. Could this be an issue with hotfix 2187?
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-07-04 : 17:28:30
In windows2k3, you have to enable network access in msdtc.
Go to Top of Page

eyechart
Master Smack Fu Yak Hacker

3575 Posts

Posted - 2007-07-04 : 19:07:42
as rmiao says, you need to configure MSDTC for network access. see http://support.microsoft.com/kb/329332 for details.


-ec
Go to Top of Page

dshelton
Yak Posting Veteran

73 Posts

Posted - 2007-07-04 : 20:42:09
I have checked the network access configuration on both servers and they are fine. MSDTC works fine with the below statement, its just the when I put the select statement in exec('') that it fails.

-- this insert runs
INSERT INTO #table
SELECT col1, col2 FROM linkedserver.database.dbo.table
Go to Top of Page
   

- Advertisement -