Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
319 views
in Technique[技术] by (71.8m points)

vba - Query on LDAP non-default domain returns error 80040E37

I designed a tool getting information from active directory and wanted to extend its use to users from another country located in another AD Domain. When I connect myself to the other AD domain in ADExplorer it works well but when I request it from VBA code I get the annoying error 80040E37 - A referral was returned from the server

Here is my code:

Dim adoCommand, ADOConnection, adoRecordset, Liste_noms, Liste_noms_split
Dim strQuery, strReturnVal, temp As String
Dim nb, i, j As Long

' Setup ADO objects.
Set adoCommand = CreateObject("ADODB.Command")
Set ADOConnection = CreateObject("ADODB.Connection")
ADOConnection.Provider = "ADsDSOObject"
ADOConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = ADOConnection

    ' Construct the LDAP syntax query.
    strQuery = "SELECT givenName, sn FROM 'LDAP://DC=Mydomain, DC=Myserver, DC=lan'"
    adoCommand.CommandText = strQuery
    ' Define the maximum records to return
    adoCommand.Properties("Page Size") = 100
    adoCommand.Properties("Timeout") = 30
    adoCommand.Properties("Cache Results") = False

    ' Run the query.
    Set adoRecordset = adoCommand.Execute
    ' Enumerate the resulting recordset.
    strReturnVal = ""
    Do Until adoRecordset.EOF = True
        ' Retrieve values and display.
            If strReturnVal = "" Then
                strReturnVal = adoRecordset.Fields(0).Value & "/" & adoRecordset.Fields(1).Value
            Else
                strReturnVal = strReturnVal & "//" & adoRecordset.Fields(0).Value & "/" & adoRecordset.Fields(1).Value
            End If
        ' Move to the next record in the recordset.
        adoRecordset.MoveNext
    Loop

    ' Clean up.
    adoRecordset.Close
    ADOConnection.Close

Do you know how I can solve this issue? It will help me a lot!

Thank you!!

question from:https://stackoverflow.com/questions/65886040/query-on-ldap-non-default-domain-returns-error-80040e37

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...