如何防止插入查询注册到分布式事务中?

发布于 2024-07-05 12:30:32 字数 205 浏览 8 评论 0原文

我在存储过程中有一个 SQL 插入查询,用于将行插入到链接服务器表中。

由于存储过程是在父事务中调用的,因此此 Insert 语句尝试使用 DTC 将行插入到链接服务器中。

我希望避免 DTC 参与其中。

有什么方法可以让插入 SQL 语句忽略事务范围(例如提示)吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

俯瞰星空 2024-07-12 12:30:37

尝试使用openquery调用链接服务器query/sp而不是直接调用
这对我有用

所以而不是
插入 ...
从 mylinkedserver.pubs.dbo.authors 选择 *

例如
声明 @TSQL varchar(8000)、@VAR char(2)
选择@VAR = 'CA'
SELECT @TSQL = 'SELECT * FROM OPENQUERY(MyLinkedServer,''SELECT * FROM pubs.dbo.authors WHERE state = ''''' + @VAR + ''''''')'

INSERT INTO .....
执行(@TSQL)

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)

一梦浮鱼 2024-07-12 12:30:36

我的建议是,将要插入的任何内容存储到临时表中,一旦过程结束,就运行跨服务器插入。 据我所知,一旦进入 SProc 执行,就无法忽略您所在的事务。

相反,如果您使用.NET 2.0 的 System.Transaction 命名空间,您可以告诉特定语句不要参与任何父作用域事务。 这需要您用代码而不是存储过程编写一些逻辑,但可以工作。

这是相关链接

祝你好运,
艾伦.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文