Error:

OLE DB provider “SQLNCLI10” for linked server “(null)” returned message “Deferred prepare could not be completed.”.
Msg 8180, Level 16, State 1, Line 1
Statement(s) could not be prepared.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ‘AS’.

In the above error the second error Msg 102 is thrown by the destination linked server, and the error 8180 is thrown by the local(source) server.

Reason for this error:
There could be synatax error in the query that is passed to the Linked Server(Other Server).

FIX/Resolution:
Execute the query that is passed to the Target server on the target server and check if there are any Syntax/Runtime errors.

[sql]
SELECT * FROM OPENROWSET(‘SQLOLEDB’,
‘Server=(local);Trusted_Connection=Yes;Database=Master’,
‘SELECT * fromsys.tables’)
[/sql]


OLE DB provider “SQLNCLI10” for linked server “(null)” returned message “Deferred prepare could not be completed.”.
Msg 8180, Level 16, State 1, Line 1
Statement(s) could not be prepared.
Msg 102, Level 15, State 1, Line 1
Incorrect syntax near ‘fromsys’.

Now when I try to execute the query (shown below) on the target server, I came to know the syntax error in the statement.
[sql]
SELECT * fromsys.tables
[/sql]

Fixed code:
[sql]
SELECT * from sys.tables
[/sql]

Now I update the Original Code as follows. Now the code runs without error.
[sql]
SELECT * FROM OPENROWSET(‘SQLOLEDB’,
‘Server=(local);Trusted_Connection=Yes;Database=Master’,
‘SELECT * from sys.tables’)
[/sql]

Applicable to SQL Server 2008,SQL Server 2005,SQL Server 2008 r2,SQL Server 2012

Leave a Reply

Your email address will not be published. Required fields are marked *