3

I have two servers: SQLSERVER01 and SQLSERVER02 and I am trying to updated data on SERVER01 from SERVER02 (SERVER01 is a linked server).

My update query is currently dynamic which looks something like this

DECLARE @SQL NVARCHAR(MAX)
DECLARE @ID INT

SET @ID = 1

Set @SQL = 'Update SERVER01.MyDatbase.dbo.MyTable
            set ModifiedDate = GetDate(), SomeOtherValue = ''xyz''
            Where Id = ' Convert(varchar(10), @ID)

If I now call

EXEC(@SQL) 

it will sometimes work, but other times it will just hang there for ages and when I run sp_active I see PREEMPTIVE_OLEDBOPS.

So, I then tried using open query as follows

Select * 
From OpenQuery(SERVER01,
               'Update SERVER01.MyDatbase.dbo.MyTable
                set ModifiedDate = GetDate(), SomeOtherValue = ''xyz''
                Where Id = 1')

but I get this error:

The OLE DB provider "SQLNCLI11" for linked server "SERVER01" indicates that either the object has no columns or the current user does not have permissions on that object.

When I run the following select query I successfully return the row I'm trying to update:

Select * 
From OpenQuery(SERVER01,
               'Select *
                From SERVER01.MyDatbase.dbo.MyTable
                Where Id = 1')

I know that the user that is running the query has permissions, but I really don't know where to go from here. I read somewhere this error has something to do with the update query not returning a row. Is there any truth to this?

How can I resolve this?

Thanks

1 Answer 1

5

Okay, I found the answer. This works successfully:

execute (@SQL) at SERVER01
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.