TSQL and OPENQUERY

  • Am having a wee problem with openquery connection.

    have added the link server and can run the query below from the SQL Server - works fine, save it as stored procedure to test, again runs fine from the SQL Server.

    SELECT

    *

    FROM OPENQUERY(ADSI,'SELECT cn,SamAccountName, ADsPath FROM ' 'LDAP://DC=DomainName,DC=com' ' WHERE bjectCategory=' 'person' ' AND objectClass=' 'user' ' ')

    trying to run the same Stored Procedure from Visual Studio and failed to run.

    I get the following message

    An error occurred while preparing the query "SELECT cn,SamAccountName, ADsPath FROM 'LDAP://DC=DomainName,DC=com' WHERE objectCategory='person' AND objectClass='user' " for execution against OLE DB provider "ADsDSOObject" for linked server "ADSI".

    the account I am using to test is a domain admin account. am not sure where to look now. I have set the admin account details in the link server settings, just for testing at the moment, as i thought it could be security issue.

    Do I need to create a DSN the computer(s) needing to run this?

    thanks in advance the help

    Cheers

    Barry

  • Hi

    In your select

    SELECT *

    FROM OPENQUERY(ADSI,'SELECT cn,SamAccountName, ADsPath FROM ' 'LDAP://DC=DomainName,DC=com' ' WHERE bjectCategory=' 'person' ' AND objectClass=' 'user' ' ')

    why do you have ' 'LDAP://DC=DomainName,DC=com' ' ? You should have already set up this in your linked server ADSI. Have you tested if your linked server object connects successfully?

    Could you try by replacing ' 'LDAP://DC=DomainName,DC=com' ' with [DATABASE].[SCHEMA].

    Regards,

    Igor

    Igor Micev,My blog: www.igormicev.com

  • Igor Micev (5/16/2014)


    Hi

    In your select

    SELECT *

    FROM OPENQUERY(ADSI,'SELECT cn,SamAccountName, ADsPath FROM ' 'LDAP://DC=DomainName,DC=com' ' WHERE bjectCategory=' 'person' ' AND objectClass=' 'user' ' ')

    why do you have ' 'LDAP://DC=DomainName,DC=com' ' ? You should have already set up this in your linked server ADSI. Have you tested if your linked server object connects successfully?

    Could you try by replacing ' 'LDAP://DC=DomainName,DC=com' ' with [DATABASE].[SCHEMA].

    Regards,

    Igor

    the Link server test connection says it successfully.

    not sure what you mean by [database].[schema]. what table am i try to get the data from? as it information in the Active Directory so i thought you would have to still use 'LDAP://DC=DomainName,DC=com'

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

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