Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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'

like image 990
Anand B Avatar asked Mar 01 '13 12:03

Anand B


2 Answers

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

like image 131
Vishal Vaishya Avatar answered Sep 23 '22 20:09

Vishal Vaishya


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.

like image 37
ajeh Avatar answered Sep 22 '22 20:09

ajeh