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

5

27

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'

Battiste answered 1/3, 2013 at 12:40 Comment(1)
I just ran into this and it turned out that the table name was case sensitive in openqueryConcinnate
P
21

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

Perjury answered 8/3, 2013 at 4:14 Comment(1)
Just ran into this recently when trying to help someone else out with a linked server. Wish the error message was more descriptive.Prefect
P
8

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.

Paronychia answered 11/5, 2016 at 17:16 Comment(0)
J
1

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!

Jotting answered 6/3, 2014 at 16:13 Comment(0)
G
1

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 :)

Gracchus answered 28/4, 2014 at 12:14 Comment(0)
A
0

I had the same issue, the problem I had was the user specified in the linked server connection did not have access to the database I was trying to access.

Anvers answered 19/2, 2019 at 15:22 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.