SQLServer2005 triggers a solution that prompts other sessions to use the context of a transaction _mssql

Source: Internet
Author: User

On MSDN, it says SQL Server 2005 does not support the presence of a local linked server (loopback linked server) in distributed transactions
A personal attempt was made by using a chained-mode access (LinkedServer) in bidirectional SQL Server access, which requires only the statements that originally visited the other database:

Copy Code code as follows:

SELECT * FROM LinkedServerA.dbo.table1

Modified to:

Copy Code code as follows:

SELECT * FROM Dbo.table1

Can.

The trigger code is as follows:

Copy Code code as follows:

Create Trigger Tgr_dressnotice_insert
On Dress_notice_config
---with encrypion–--encryption triggers
After insert----UPDATE level Trigger
As
Begin
--as raisError (' Tgr_dressnotice_insert triggers are triggered ', 16, 10);
/* Define Variable * *
Declare @sDBServer char (20)/* For storing the destination database * *
DECLARE @sSql varchar (600)
DECLARE @server varchar (100)
DECLARE @oadb varchar (100)

Select @oadb =db_server from Dic_organ where valid= ' 1 ' and rank in (' A ', ' B ') and organ_id= ' 000000 '
Set @server =rtrim (@oadb) + '. Dbo.spoa_exec_string '

/*define cursor*/
DECLARE db_cursor cursor FOR
Select Db_server from Dic_organ where valid= ' 1 ' and rank in (' A ', ' B ') and organ_id<> ' 000000 '

/*open cursor*/
OPEN Db_cursor
FETCH NEXT from Db_cursor
Into @sDBServer

while (@ @Fetch_status = 0)
Begin
/* Synchronize the data to the database in each branch
Set @sSql = ' Delete from ' + RTRIM (@sDBServer) + '. Dbo.dress_notice_config '
Print @sSql
EXEC @server @sSql
Set @sSql = ' INSERT INTO ' + RTRIM (@sDBServer) + '. Dbo.dress_notice_config select * from Dress_notice_config '
Print @sSql
EXEC @server @sSql

FETCH NEXT from Db_cursor
Into @sDBServer
End

--Finally close the cursor
Close Db_cursor
Deallocate db_cursor
End
Go

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.