openrowset and variables for querying AD help

  • here is my current query:

    SELECT Name, displayName,givenname,distinguishedName, SAMAccountName

    FROM

    OPENROWSET('ADSDSOObject','adsdatasource'; 'login';'password',

    'SELECT Name, displayName,givenname,distinguishedName, SAMAccountName

    FROM ''LDAP://DC=domain,DC=local'' ')

    This runs perfect if I manually fill in the login and password. Of coarse I cant just put @login or @password in there, but I need to find a way to get them in there..

    So I did

    DECLARE @login nvarchar(50), @pass nvarchar(50), @TSQL nvarchar(4000)

    SELECT @login = 'login'

    SELECT @pass = 'password'

    SELECT @TSQL = 'SELECT * FROM OPENROWSET('ADSDSOObject','adsdatasource';'' + @login + ',' + @pass ',' FROM ''LDAP://DC=domain,DC=local'' ')'

    EXEC (@TSQL)

    but im getting errors about 'adsdatasource' etc etc. Im sure Im stacking up the single quotes wrong..

    I simply want to pass the login and the password to the openrowset query.

    Thanks to anyone that can help.

  • I should add that Im not stuck on openrow set but I cant seem to pass login credentials to openquery when using a linked server and thats why im trying to use openrowset.

Viewing 2 posts - 1 through 1 (of 1 total)

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