OpenRowSet and trigger-distributed transaction problems

Source: Internet
Author: User
First look at the example:
Assume that the local Table A (a_nam varchar (5), a_add varchar (10), Col INT)
Every insert operation forgets the Mabel under the Minerva server to insert the same data in table.

Create trigger insert_trig1 on [DBO]. [A]
For insert
As
Set
Insert into OpenRowSet ('sqloledb', 'minerva '; 'sa'; '00', Mabel. DBO. a) Select * From inserted

Insert into a values ('5', '55', 1)
/*
Server: MSG 7395, level 16, state 2, procedure insert_trig1, line 6
Cannot activate the nest transaction of ole db Provider 'sqloledb. Because the xact_abort option has been set to off, you must specify the nest transaction to be used.
[OLE/DB Provider returned message: More actions cannot be triggered in this work segment.
]
Ole db zookeeper traces errors [OLE/DB Provider 'sqlodb' itransactionlocal: starttransaction returned 0x8004d013: isolevel = 4096].
*/

Modify:
Alter trigger insert_trig1 on [DBO]. [A]
For insert
As
Set
Set xact_abort on
Insert into OpenRowSet ('sqloledb', 'minerva '; 'sa'; '00', Mabel. DBO. a) Select * From inserted

Insert into a values ('5', '55', 1)
/*
(1 row (s) affected)
*/
OK!

The following describes distributed transactions and triggers in advance:
1. Start Distributed Transaction Ms DTC
2. Set xact_abort on in the process or trigger

Problem:
Is set xact_abort a required transaction?
A:
No!
Set xact_abort
Specifies whether Microsoft SQL Server automatically rolls back the current transaction when a running error occurs in a Transact-SQL statement.
Syntax
Set xact_abort {on | off}
Note
When set xact_abort is on, if a running error occurs in a Transact-SQL statement, the entire transaction is terminated and rolled back. When it is off, only the wrong Transact-SQL statement is returned, and the transaction will continue to be processed. Compilation errors (such as syntax errors) are not affected by set xact_abort.

For most Ole databasesProgram(Including SQL Server), xact_abort must be set to on in implicit or explicit transaction data modification statements. The only case where this option is not required is when the Provider supports nested transactions. For more information, see distributed queries and distributed transactions.

Set xact_abort is set during execution or running, rather than during analysis.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.