Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 786
  • Last Modified:

Help with ADO ADSI

hiya--

i am trying to run this code that i found on the micrsoft support site.

HOWTO: Work Around the Limitation that ADO MaxRecord Is Not Implemented in DS OLEDB Provider ADsDSOObject (Q269361)

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q269361


it is supposed to connect to the exhange server (ldap) and pull peoples information out.

when the number of results is low (anything 80 and under so far) it seems to work. however, when i try to pull info when the user name is smith (about 530 results)
i get this error:

Data provider or other service returned an E_FAIL status.
 0
-2147467259
Microsoft Cursor Engine


my code is listed below. im gonna keep digging but any help would be great.

thanks --p



Option Explicit

Private Sub Form_Load()

    On Error GoTo err

    Dim cn As New ADODB.Connection, cmd As New ADODB.Command, rs As New ADODB.Recordset
   
    Dim lcConn As String
    Dim i As Integer
    Dim j As Integer
   
    lcConn = "Provider=ADsDSOObject"
    With cn
        .Open lcConn
    End With
   
    With rs
       
        Set .ActiveConnection = cn
        .CursorLocation = adUseClient
        .CursorType = adOpenStatic
        .LockType = adLockOptimistic
        .PageSize = 5 '<--- this is the value to change for how many records to return.
        .CacheSize = .PageSize
        .Open "<GC://U110875S1:389>;(sn=smith);" & _
            "cn,mail,givenName;subtree", , adOpenStatic, adLockReadOnly, adCmdText
        .AbsolutePage = 1
        .Filter = adFilterFetchedRecords
    End With
   
    For i = 0 To rs.RecordCount - 1
        Debug.Print i + 1 & " "
        For j = 0 To rs.Fields.Count - 1
            Debug.Print rs.Fields(j).Value,
        Next
        Debug.Print
        rs.MoveNext
    Next
    Exit Sub

err:

    Dim z As Integer
   
    For z = 0 To cn.Errors.Count - 1
        Debug.Print cn.Errors.Item(i).Description
        Debug.Print cn.Errors.Item(i).NativeError
        Debug.Print cn.Errors.Item(i).Number
        Debug.Print cn.Errors.Item(i).Source
        Debug.Print cn.Errors.Item(i).SQLState
    Next z

End Sub
0
pipe
Asked:
pipe
  • 8
  • 7
1 Solution
 
rkot2000Commented:
1. you need to use ado 2.5, 2.6 has bud you can search support.microsoft.com

2. you should try use command object because rs has some problems :


Private Function mfGetActiveDirectoryData(ByVal lvsLetter As String) As ADODB.Recordset
 
 
  Dim ljrsAD As ADODB.Recordset
  Dim ljcmAD As ADODB.Command
 
  Dim lvsADQuery As String
  Dim lvsWhere As String
 
  On Error GoTo Error_
 
  lvsWhere = UCase(lvsLetter) & "*"
 
 
  Call msOpenConnectionAD
  Set ljcmAD = New ADODB.Command
  Set ljcmAD.ActiveConnection = mjcnAD
  ljcmAD.Properties("Page Size") = 100
 
 
    'Alias:    samAccountName
    'First Name: givenname
    'Last Name:  sn
    'Phone Number: TelephoneNumber
    'Department: Department
    'Suite extensionAttribute8
    'city I
    'zip:    postalcode
    'state:    st
    'Address streetaddress
    'Title:    Title
    'Assisant: assistant
    'Company : Company
    'Office: physicalDeliveryOfficeName
  lvsADQuery = gcsADServer & _
  ";(&(objectClass=user)(objectCategory=person)(sn=" & lvsWhere & "));" & _
  "sn,givenName,msExchHideFromAddressLists,samAccountName,mail,telephoneNumber,department,extensionAttribute8,streetaddress,l,postalcode,st,title,assistant,physicalDeliveryOfficeName,Company;subtree"
 
  ljcmAD.CommandText = lvsADQuery
  ljcmAD.CommandTimeout = 3000
  Set ljrsAD = New ADODB.Recordset
  ljrsAD.CursorLocation = adUseClient
   
  'due to the bug with AD we must use command object to execute call
  'or result set will be limited to the first 1000 rows
  ljrsAD.Open ljcmAD, , adOpenStatic, adLockReadOnly, adAsyncExecute
 
  Do While ljrsAD.State = adStateExecuting
    Call Wait
    DoEvents
  Loop
 
  Set ljrsAD.ActiveConnection = Nothing
  Set ljcmAD = Nothing
 
  Call msCloseConnectionAD(geShowError)
 
  ljrsAD.Save AppPath & CurrentDateFolder & "AD_" & lvsLetter & ".rs"
  Set mfGetActiveDirectoryData = ljrsAD
 
Exit_:
  Call AppendToLog("  - " & lvsLetter & " Downloaded rows : " & ljrsAD.RecordCount, awpProcess, True)
  Exit Function

Error_:
  'catch error
  Dim luError As guError
  luError = ErrorToUDT
 
  Call msCloseConnectionAD(geHideError)
  Call ForwardError(luError, mfErrorSource("mfGetActiveDirectoryData"))
 
End Function


0
 
pipeAuthor Commented:
can i see the rest of your code. im confused in a few places. for instance you call to

Call Wait


thanks - p
0
 
rkot2000Commented:
Call Wait - it just to keep cpu at low level

in the module :

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Function Wait(Optional ByVal lvlMilliseconds As Long = 1000)
  Call Sleep(lvlMilliseconds)
End Function
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
pipeAuthor Commented:
ok, hopefully, i am almost there. when i call the open method of the rs i get the following error.

"One or more errors occurred during processing of command."


here is my code:
thanks!!!


Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Public Function Wait(Optional ByVal lvlMilliseconds As Long = 1000)
    Call Sleep(lvlMilliseconds)
End Function

Private Sub Form_Load()

    Dim rs As ADODB.Recordset
    Set rs = mfGetActiveDirectoryData("master")

End Sub

Private Function mfGetActiveDirectoryData(ByVal lvsLetter As String) As ADODB.Recordset
   
    Dim ljrsAD As ADODB.Recordset
    Dim ljcmAD As ADODB.Command
    Dim lvsADQuery As String
    Dim lvsWhere As String
    Dim mjcnAD As ADODB.Connection
   
    Const SERVER = "USA0875MS1:389"
 
    On Error GoTo Error_

        Set mjcnAD = New ADODB.Connection
        mjcnAD.Open "Provider=ADsDSOObject"

        lvsWhere = UCase(lvsLetter) & "*"
 
        'Call msOpenConnectionAD
 
        Set ljcmAD = New ADODB.Command
        Set ljcmAD.ActiveConnection = mjcnAD
        ljcmAD.Properties("Page Size") = 100
 
        lvsADQuery = SERVER & _
            ";(&(objectClass=user)(objectCategory=person)(sn=" & lvsWhere & "));" & _
            "sn,givenName,msExchHideFromAddressLists,samAccountName,mail,telephoneNumber," & _
            "department,extensionAttribute8,streetaddress,l,postalcode,st,title,assistant," & _
            "physicalDeliveryOfficeName,Company;subtree"
 
        ljcmAD.CommandText = lvsADQuery
        ljcmAD.CommandTimeout = 3000
       
        Set ljrsAD = New ADODB.Recordset
        ljrsAD.CursorLocation = adUseClient
   
        'due to the bug with AD we must use command object to execute call
        'or result set will be limited to the first 1000 rows
        ljrsAD.Open ljcmAD, , adOpenStatic, adLockReadOnly, adAsyncExecute
 
        Do While ljrsAD.State = adStateExecuting
            Call Wait
            DoEvents
        Loop
 
        Set ljrsAD.ActiveConnection = Nothing
        Set ljcmAD = Nothing
 
        'Call msCloseConnectionAD(geShowError)
        'ljrsAD.Save AppPath & CurrentDateFolder & "AD_" & lvsLetter & ".rs"
        Set mfGetActiveDirectoryData = ljrsAD
 
Exit_:
   
    'Call AppendToLog("  - " & lvsLetter & " Downloaded rows : " & ljrsAD.RecordCount, awpProcess, True)
    Exit Function

Error_:
 
    'catch error
    'Dim luError As guError
    'luError = ErrorToUDT
 
    'Call msCloseConnectionAD(geHideError)
    'Call ForwardError(luError, mfErrorSource("mfGetActiveDirectoryData"))
    Debug.Print err.Description
 
End Function
0
 
pipeAuthor Commented:
i changed my server to:

Const SERVER = "<GC://USA0875MS1:389>"

it opens fine now, however, i am getting an "uspecified error" in the wait, doevent loop.
0
 
pipeAuthor Commented:
yea, the status turns to "Unspecified error" the second time thru the loop.

 


        Do While ljrsAD.State = adStateExecuting
            Call Wait
            DoEvents
        Loop
0
 
rkot2000Commented:
I neeed adsi version.
0
 
rkot2000Commented:
try to reload adsi2.5 from this location and reboot your pc.
http://www.microsoft.com/ntserver/nts/downloads/other/ADSI25/default.asp
0
 
rkot2000Commented:
what is U110875S1:389

389 in the server name i have the following :
Public Const gcsADServer As String = "<GC://A0001-HOD0001-D>"
just nt server name
0
 
pipeAuthor Commented:
the 389 is the ldap port. lemmie try and get the new adsi and see what happens. i am on windows xp using ado 2.5 instead of 2.7 now.
0
 
pipeAuthor Commented:
i cant find adsi for xp. i may have to find a windows 200 box to play on.
0
 
pipeAuthor Commented:
when i take the port out (:389) it says that it cannot find the table when i hit the wait loop.
0
 
rkot2000Commented:
i am using 2000 and you have my code... :)
0
 
pipeAuthor Commented:
i hear that. i appreciate the help. nothing is easy here at work. thx.

one last thing i want to check. can i see you code for this. it's the only thing that may be different.

Call msOpenConnectionAD
0
 
rkot2000Commented:
Private Sub msOpenConnectionAD()
  On Error GoTo Error_
  Dim luError As guError
  Set mjcnAD = New ADODB.Connection
 
  With mjcnAD
    .ConnectionTimeout = 3000
    .Provider = "ADSDSOObject"
    .Open "Active Directory Provider"
    .CommandTimeout = 3000
  End With
 
Exit Sub

Error_:
  luError = ErrorToUDT
  Call ForwardError(luError, mfErrorSource("msOpenConnectionAD"))
End Sub
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now