"Deferred prepare could not be completed" error when using local database as linked server

64,042

Solution 1

Have you missed something in your object name. It should be always like Database.User.ObjectName (for e.g. Northwind.dbo.Customers)

Give complete object name when running queries via Linked servers.

Query for Stored Procedure may be like this when executing on Linked Servers:

Select  *
From    OPENQUERY([COM2\SQLEXPRESS], 'Exec Northwind.dbo.CustOrderHist ''CUST1''') as TB1

Check with options like SET FMTONLY OFF when executing Stored procedure.

Follow this link for OPENQUERY: http://msdn.microsoft.com/en-us/library/ms188427.aspx

Solution 2

Even if you have named a column incorrectly in your query, you are going to see this error. Example:

select *
from openquery(
     lnksrv
    ,'select top 10 * from db.schema.table where colunm = 10'
)

and the column name is column, not colunm.

Bottom line is check the actual query to be sent to the remote server for correctness first, then wrap it in openquery and re-test.

Solution 3

I had the same error trying to query through a linked server. However, I was querying a view on the target server, not a stored procedure.

The target server's view was created like this:

CREATE VIEW vABC AS
    SELECT ... FROM Table1
    UNION ALL
    SELECT ... FROM Table2

To fix the problem, I did an alter view, and wrapped the two UNION statements in a subquery, like this:

CREATE VIEW vABC AS
    SELECT * FROM (
        SELECT ... FROM Table1
        UNION ALL
        SELECT ... FROM Table2
    ) T

Must be some metadata issue with the original view.

Hope this helps you!

Solution 4

Same problem for me: I resolved it just fixing the "target" object, that was not named correctly.

In my case I was searching for [testDb].[Business.Customer] table, but the correct name was [testDb].[Business].[Customer]...same error as yours:

Il provider OLE DB "SQLNCLI10" per il server collegato "RIBOWEB10\SQLEXPRESS" ha restituito il messaggio "Deferred prepare could not be completed.".

I think SQL Server tries to dynamically resolve names that don't match directly with real objects, but not sure of that.

Quite easy, I hope this helps :)

Share:
64,042

Related videos on Youtube

Anand B
Author by

Anand B

Updated on July 09, 2022

Comments

  • Anand B
    Anand B almost 2 years

    I created a Linked Server from my local Sql Server, as given in

    http://sqlserverplanet.com/dba/local-linked-server

    However when I try to execute a stored procedure in Linked Server, it throws:

    Deferred prepare could not be completed
    

    error and invalid object name 'table name'

    • gordy
      gordy about 9 years
      I just ran into this and it turned out that the table name was case sensitive in openquery
  • Dave Johnson
    Dave Johnson about 11 years
    Just ran into this recently when trying to help someone else out with a linked server. Wish the error message was more descriptive.