OpenRowset Only Getting Results from localhost

  • I am running the following SQL Query:

    SELECT

    p.*

    FROM

    OPENROWSET

    ('SQLOLEDB', 'Trusted_Connection=yes; Integrated Security=SSPI;

    DataSource=ServerName;Initial_Catalog=master;'

    , 'SELECT @@SERVERNAME AS ServerName, SUBSTRING(s.name, 1, 40) AS Expr1, DATEDIFF(dd, b.backup_start_date, GETDATE())

    AS Expr3, GETDATE() AS RD, b.backup_start_date, b.type

    FROM master.dbo.sysdatabases s LEFT OUTER JOIN

    msdb.dbo.backupset b ON s.name = b.database_name') AS p

    But it queries the local server, not the Server specified at DataSource. Any one got any ideas why ?

  • You said

    DataSource=ServerName

    Try

    Server=ServerName

  • Still get the same result

  • The other thing I did (which I didn't realise was significant) was to remove the line-break in the connection string.

    ('SQLOLEDB', 'Trusted_Connection=yes; Integrated Security=SSPI;Server=ServerName;Initial_Catalog=master;'

    Re-adding the line break causes the query to run against the local host.

  • Thank you very much, this worked.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply