0

I am having an issue when trying to do an update via a linked server. Error is the following:

OLE DB provider "MSDASQL" for linked server "**LINKED_SERVER_NAME" returned message "Data provider or other service returned an E_FAIL status.".
Msg 7330, Level 16, State 2, Line 1
Cannot fetch a row from OLE DB provider "MSDASQL" for linked server "LINKED_SERVER_NAME".

I have no problem selecting data but any time I try to do an update it fails. My update code:

Update [LINKED_SERVER_NAME]...[Table_Name]
SET post_content = 'alert'
where ID = 5061

This is my select statement which DOES work:

select top 100 * from [LINKED_SERVER_NAME]...[Table_Name] where ID = 5061

I am using:

  • Microsoft SQL Server Management Studio 2008
  • Trying to connect from MS SQL -> MySQL via ODBC Connector 5.2 (5.1 has same issue)

UPDATE I have tried to use "OPENQUERY" -> this does not work either

3
  • From memory the syntax you are looking for is: UPDATE OPENQUERY(LINKED_SERVER_NAME, 'SELECT post_content FROM Table_Name WHERE ID = 4061') SET post_content = 'alert' - see msdn.microsoft.com/en-us/library/ms188427.aspx Commented Oct 3, 2012 at 20:54
  • Is openquery a new thing. I was successfully able to do this about 2 years ago. I just tried recently which is where I ran into problems. Commented Oct 3, 2012 at 20:55
  • I've always had to do it when the linked server was a non-SQL Server instance. Otherwise if the Linked Server is another SQL Server instance, standard ANSI SQL seems (mostly) okay. One other thing to check, I guess, is if the account details the Linked Server have been set up with have UPDATE permissions on the underlying TABLE_NAME. Commented Oct 3, 2012 at 20:57

1 Answer 1

1

OPENQUERY is not new but it is far more reliable when dealing with non-microsoft linked servers.

UPDATE OPENQUERY (LINKED_SERVER_NAME, 'SELECT post_content FROM Table_Name WHERE ID = 5061') 
SET post_content = 'alert'; 
  • Do not use [ ] square brackets in mysql queries; you can use apostrophe instead.
  • Check that you have update permissions on the table.
  • Try running the update directly on a mysql connection. This may be an error not related to linked servers.
  • Is the mysql table a view? It may not be configured correctly as an updatable view. MySQL CREATE VIEW Syntax

If this still doesn't solve it, paste your actual openquery code into the question.

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.