0

I'm working in a SP and I got two tables in different servers, one is the main and the other is a copy but whit less columns, all I want is to run the SP every 5 min over the main table in order to validate if new records has been created, if yes take those new records and insert them into the copy table, that resides in the other server.

Searching a solution I've found this script wich works ok in the same server, but when I try to run it with the linked server it fails....please somebody help me with this.

This is the error that a get....

OLE DB provider "SQLNCLI" for linked server "ESDBCGW001T" returned message "The partner transaction manager has disabled its support for remote/network transactions.". Msg 7391, Level 16, State 2, Procedure sp_newrecords, Line 37 The operation could not be performed because OLE DB provider "SQLNCLI" for linked server "LINKEDSERVER" was unable to begin a distributed transaction.

All configurations are perfect, and when I run the insert without the variables runs fine,I mean, instead of @val1, @val2 and @val3 I use real values 1, 'A', 'B'.

USE [XXX]
GO
/****** Object:  StoredProcedure [dbo].[sp_newrecords]    Script Date: 03/02/2015 11:11:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      <>
-- Create date: <>
-- Description: <Description,,>
-- =============================================


ALTER PROCEDURE [dbo].[sp_newrecords]


    -- Add the parameters for the stored procedure here

AS
BEGIN

DECLARE @val1 int
DECLARE @val2 nvarchar(50)
DECLARE @val3 nvarchar(50)


    SET NOCOUNT ON;

    -- Insert statements for procedure here
DECLARE mycur1 CURSOR for

 select empid,fname,lname from employee
 where empid = 508 --this is for test only

 OPEN mycur1

 FETCH NEXT FROM mycur1 INTO @val1, @val2 , @val3



 WHILE @@Fetch_Status = 0

 BEGIN



 begin tran /* default read committed isolation level is fine */

    if not exists (select * from openquery (linkedserver,'select * from DBNAME.dbo.Employee_backup'))
     --insert employee_backup values (@val1, @val2 , @val3)
    begin

     INSERT into [linkedserver].[DBNAME].[dbo].[Employee_backup] values (@val1, @val2 , @val3)

    end

 /*if not exists (select * from employee_backup with (updlock, rowlock, holdlock)
                     where employee_backup.empid = @val1 
                        and employee_backup.fname = @val2 )
     --insert employee_backup values (@val1, @val2 , @val3)
     INSERT [LINKEDSERVER].[DBNAME].[dbo].[Employee_backup] values (@val1, @val2 , @val3)*/

 --else
 --  /* update */

 commit /* locks are released here */

 FETCH NEXT FROM mycur1 INTO @val1, @val2 , @val3`enter code here`

 END

 CLOSE mycur1

 DEALLOCATE mycur1

END
Jeroen Mostert
  • 27,176
  • 2
  • 52
  • 85
emancia
  • 1
  • 2

2 Answers2

0

Your database admin would need to allow that permission on the target server. Personally, I would simply replicate the table from one server to the other and then the stored procedure would run against the replicated data.

If you absolutely need to go cross server, please refer to this SO question.

Community
  • 1
  • 1
UnhandledExcepSean
  • 12,504
  • 2
  • 35
  • 51
0

why not just use replication for something like this?

Might need to enable Distributed Transaction Coordinator (DTC) for your specific problem https://technet.microsoft.com/en-us/library/cc759136%28v=ws.10%29.aspx

In addition to ensuring DTC is enabled, you should be using begin distributed tran rather than begin tran

See:

https://msdn.microsoft.com/en-us/library/ms188386.aspx

Kritner
  • 13,557
  • 10
  • 46
  • 72