Question

I have the same table in two different sql servers (one is SqlServer 2000 and the other 2008).

I'm using sql server management studio.

I want that each time an insert is made on a table in the SqlServer 2000 table (Table_1) a trigger occurs and the record would also be inserted to the same table in the SqlServer 2008 table (also Table_1).

the sql server 2008 is defined as a linked server, and it is possible to run queries and perform inserts on the 2008 db from the 2000 db connection using sql server management studio.

the trigger is defined as follows :

ALTER TRIGGER [dbo].[trgrTable] 
   ON  [dbo].[Table_1]
   AFTER INSERT
AS 
BEGIN

 INSERT INTO [TLVSQL].[AVI_DEV].[dbo].[Table_1](ID, Value)
      SELECT INSERTED.ID AS ID, INSERTED.Value AS Value
      FROM INSERTED

END

the [TLVSQL].[AVI_DEV] is the 2008 db name.

But every time i perform an insert on the 2000 table i get a message that the insert failed to commit due to "sqloledb was unable to begin a distributed transaction linked server ...".

The security delegation of the linked server is well defined, i explicitly set the security credentials to a user/password of a db_owner.

What am i doing wrong ? Is there another way of doing what i ask ?

thank you.

Was it helpful?

Solution

Perform inserts from a trigger into a table on linked server - bad decision. This will great affects on insert performance in the source table ([dbo].[Table_1]) and also there is a distributed transaction, and configuring servers for support distributed transactions - nightmare.

One possible solution is:

  1. On the source server you can create a synchronization queue table. For example:

    CREATE TABLE dbo.SyncQueue
    (
        QueueId INT IDENTITY(1,1),        
        KeyForSync INT, -- Primary key value of record in dbo.SourceTable
        SyncStatus INT  -- statuses can be: 0 - New, 1 - Synchronized, 2 - Error
    )
    
    suppose you source table is
    
    CREATE TABLE dbo.SourceTable
    (
            Key INT, -- primary key of the table
            Data varchar(xxx)
    )
    
  2. Triger on dbo.SourceTable can quickly insert into dbo.SyncQueue record Key that you need synchronize

  3. Some periodically performed stored procedure can then insert records from the queue in table on the linked server.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top