Search code examples
sql-serveropenrowset

deferred prepare could not be completed, 3 SQL Servers


I have 3 SQL Servers, and I'm getting strange behavior with OpenRowset.

Given:

  • Server 1 = 192.168.1.1,
  • Server 2 = 192.168.1.2,
  • Server 3 = 192.168.1.3,
  • Server 4 = 192.168.1.4

SQL:

SELECT a.* 
FROM OPENROWSET('SQLOLEDB', 
                'Data Source=192.168.1.1;Persist Security 
Info=True;uid=sa;pwd=password',  
                'SELECT * FROM  dfs_database.dbo.dfs_vehicledata ') AS a; 

Here is the strange part: if I run the above SQL statement on servers .3 and .4, everything works fine.

However, if I run the SQL statement on server .2, I get:

OLE DB provider "SQLNCLI11" for linked server "(null)" returned message "Deferred prepare could not be completed.".

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

Msg 208, Level 16, State 1, Line 7
Invalid object name 'dfs_database.dbo.dfs_vehicledata'.

So what could make one relationship not work when the others work fine? Any ideas? They are all SQL Server express, and all report having SQLNCLI11 providers.


Solution

  • Using OpenRowSet it look like this:

    sp_configure 'Show Advanced Options', 1
    GO
    RECONFIGURE
    GO
    sp_configure 'Ad Hoc Distributed Queries', 1
    GO
    RECONFIGURE
    GO
    OPENROWSET('SQLNCLI', 
    'Server=ipHere\ExtentionNameifHas;Database=DBName;Uid=userName;PWD=Password;'
    ,'SET FMTONLY OFF;SET NOCOUNT ON;SELECT * FROM  
    dfs_database.dbo.dfs_vehicledata'