I'm trying to programmatically monitor transactional replication of several SQL databases. So far, I have the following code snippet but it seems to be missing something:
SELECT * INTO #PublisherInfo FROM OPENROWSET('SQLOLEDB', 'SERVER=servername;TRUSTED_CONNECTION=YES;', 'SET FMTONLY OFF; SET NOCOUNT ON; EXEC distribution.dbo.sp_replmonitorhelppublisher WITH RESULT SETS (publisher, distribution_db, status, warning, publicationcount, returnstamp)')
But I'm receiving the following error:
OLE DB provider "SQLNCLI11" for linked server "(null)" returned message "Deferred prepare could not be completed.".
Msg 8180, Level 16, State 1, Line 12
Statement(s) could not be prepared.
Msg 102, Level 15, State 1, Line 13
Incorrect syntax near 'publisher'.
Any help would be appreciated. Thx!