Msg 8180, Level 16, State 1, Line 1 Statement(s) could not be prepared.

Posted on : 14-05-2012 | By : Devi Prasad | In : Msg 8180, SQL Errors

0



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.

SELECT * FROM OPENROWSET('SQLOLEDB',
                         'Server=(local);Trusted_Connection=Yes;Database=Master',
                         'SELECT * fromsys.tables')


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.

SELECT * fromsys.tables

Fixed code:

SELECT * from sys.tables

Now I update the Original Code as follows. Now the code runs without error.

SELECT * FROM OPENROWSET('SQLOLEDB',
                         'Server=(local);Trusted_Connection=Yes;Database=Master',
                         'SELECT * from sys.tables')

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




Reference : Devi Prasad (sqlserverlearner.com)

Do you like my blog?

If you liked reading this blog, please help spread the word by sharing this blog with your friends.



Need Help On SQL Server?

Cannot Find Solution to your problem (or) If you are looking for some help on SQL Server. Dont worry Click Here to Post your question and solve your issue.




Your Ad Here


Tags: ,