Solved

Help with ADO ADSI

Posted on 2002-04-08
15
758 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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
 
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 Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

735 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