Question

I have a SQL Insert query inside a stored proc, for inserting rows into a linked server table.

Since the stored proc is getting called within a parent transaction, this Insert statement tries to use a DTC for inserting rows into the linked server.

I would like to avoid DTC from getting involved.

Is there any way I can do that (like a hint) for the Insert SQL statement to ignore transactional scope?

Was it helpful?

Solution

My suggestion is that you store whatever you want to insert into a staging table, and once the procedure is over run the cross server insert. To my knowledge there is no way of ignoring the transaction you are in once you are within the SProc execution.

In contrast, if you use .NET 2.0's System.Transaction namespace, you can tell specific statements not to participate in any parent scope transaction. This would require you to write some of your logic in code rather than stored procedures, but would work.

Here's a relevant link.

Good luck, Alan.

OTHER TIPS

Try using openquery to call the linked server query/sp instead of direct calling That worked for me

so instead of insert into ... select * from mylinkedserver.pubs.dbo.authors

e.g. DECLARE @TSQL varchar(8000), @VAR char(2) SELECT @VAR = 'CA' SELECT @TSQL = 'SELECT * FROM OPENQUERY(MyLinkedServer,''SELECT * FROM pubs.dbo.authors WHERE state = ''''' + @VAR + ''''''')'

INSERT INTO ..... EXEC (@TSQL)

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