Solved

Help with ADO ADSI

Posted on 2002-04-08
15
743 Views
Last Modified: 2008-02-01
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
Comment
Question by:pipe
  • 8
  • 7
15 Comments
 
LVL 5

Expert Comment

by:rkot2000
ID: 6925694
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
 

Author Comment

by:pipe
ID: 6925849
can i see the rest of your code. im confused in a few places. for instance you call to

Call Wait


thanks - p
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6925861
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
 

Author Comment

by:pipe
ID: 6925913
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
 

Author Comment

by:pipe
ID: 6925925
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
 

Author Comment

by:pipe
ID: 6925931
yea, the status turns to "Unspecified error" the second time thru the loop.

 


        Do While ljrsAD.State = adStateExecuting
            Call Wait
            DoEvents
        Loop
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6925934
I neeed adsi version.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Expert Comment

by:rkot2000
ID: 6925939
try to reload adsi2.5 from this location and reboot your pc.
http://www.microsoft.com/ntserver/nts/downloads/other/ADSI25/default.asp
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6925941
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
 

Author Comment

by:pipe
ID: 6925967
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
 

Author Comment

by:pipe
ID: 6925981
i cant find adsi for xp. i may have to find a windows 200 box to play on.
0
 

Author Comment

by:pipe
ID: 6926003
when i take the port out (:389) it says that it cannot find the table when i hit the wait loop.
0
 
LVL 5

Accepted Solution

by:
rkot2000 earned 135 total points
ID: 6926042
i am using 2000 and you have my code... :)
0
 

Author Comment

by:pipe
ID: 6926510
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
 
LVL 5

Expert Comment

by:rkot2000
ID: 6928144
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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now