Toon posts:

[ASP/ADSI] waarom is het zo ongelooflijk traag?

Pagina: 1
Acties:
  • 121 views sinds 30-01-2008
  • Reageer

Verwijderd

Topicstarter
Ik ben bezig met een soort van verkoopsysteem waar de gebruikersdatabase gekoppeld moet worden aan een NT-domein. Nu gebruik ADSI om de gebruikers van een bepaalde NT-groep op te vragen met het volgende stukje code:
code:
1
2
3
4
5
6
7
8
9
10
dim myDomain
Dim member

set myDomain = getObject("WinNT://Domain/Employees")

for each member in myDomain.members
    if(member.class = "User") then
        response.write("<li><a href=""."">" & member.fullName & "</a></li>")
    end if
next

Werkt prima, het is alleen zo baggertraag :(

Is er een manier om het te versnellen (een bepaalde config ofzo?) Anders moet ik er nog maar eens over nadenken of ik het wel op deze manier moet doen

Verwijderd

Topicstarter
ka.....*bump*

Verwijderd

Stap over op Win2000

Verwijderd

Topicstarter
Dat is helaas (nog) geen optie... Applicatie wordt gebouwd voor bedrijf en dat is nog niet in de planning...

Is de snelheid op win2000 wat dat betreft flink verbeterd dan?

Verwijderd

win2000 is volgens mij sneller, inderdaad.

Maar ik bedenk me dat je voor jou probleem wellicht ook ADSI in ADO kunt gebruiken. Voobeeldje:
code:
1
2
3
Set command = CreateObject("ADODB.Command")
Set command.ActiveConnection = oConnect
command.CommandText = "SELECT AdsPath, fullName FROM WinNT://Domain/Employees' WHERE objectClass = 'Members'"

Je moet even in MSDN graven, maar dan heb je ook wat.

Verwijderd

Op vrijdag 14 december 2001 12:57 schreef Doekman het volgende:
Stap over op Win2000
en dan Windows 2000 Advanced Server SP 2 ;) :7

Verwijderd

Topicstarter
Op maandag 17 december 2001 09:37 schreef Doekman het volgende:
win2000 is volgens mij sneller, inderdaad.

Maar ik bedenk me dat je voor jou probleem wellicht ook ADSI in ADO kunt gebruiken. Voobeeldje:
code:
1
2
3
Set command = CreateObject("ADODB.Command")
Set command.ActiveConnection = oConnect
command.CommandText = "SELECT AdsPath, fullName FROM WinNT://Domain/Employees' WHERE objectClass = 'Members'"

Je moet even in MSDN graven, maar dan heb je ook wat.
Daar was ik onderhand ook al een beetje mee aan het kloten, maar krijg het tot nog toe niet werkende... Ik kan maar niet uitvogelen hoe dat oConnect object geinitialiseerd moet worden (welke properties...)

Met de volgende code krijg ik deze error: One or more errors occurred during processing of command.
code:
1
2
3
4
5
6
7
8
set oConnect = CreateObject("ADODB.Connection")
oConnect.Provider = "ADsDSOObject"
oConnect.Open "ADs Provider"

set command = CreateObject("ADODB.Command")
set command.ActiveConnection = oConnect
command.CommandText = "SELECT AdsPath, fullName FROM WinNT://ITH/CPTEmployees' WHERE objectClass = 'Members'"
set rs = command.execute

:?

Verwijderd

Ik heb wat op m'n lokale MSDN Library gevonden. Op msdn.microsoft.com/library vond ik het niet, dus hier een paste:
Platform SDK: Directory Services
Searching with ActiveX Data Objects (ADO)
The ActiveX® Data Object model consists of the following objects:

Connection
An open connection to an OLE DB data source such as ADSI.
Command
Defines a specific command to execute against the data source.
Parameters
An optional collection for any parameters to provide to the command object.
Recordset
A set of records from a table, command object, or SQL syntax. A recordset can be created without any underlying Connection object.
Field
A single column of data in a recordset.
Property
A collection of values supplied by the provider for ADO.
Error
Contains details about data access errors, refreshed for each time an error occurs in a single operation.
In order for ADO to communicate with ADSI, you must have at least two ADO objects: Connection and RecordSet. These ADO objects serve to authenticate users and enumerate results, respectively. Typically, you will also use a Command object to maintain an active connection, specify query parameters, such as page size and search scope, and execute a query.

The Connection object loads the OLE DB provider, and validates user credentials. In Visual Basic, you call CreateObject("ADODB.Connection") to create an instance of a Connection object, and then set the Provider property of the Connection object to "ADsDSOObject". "ADODB.Connection" is the ProgID of the Connection object and "ADsDSOObject" is the name of the OLE DB provider in ADSI. If no credentials are specified, the credentials of the currently logged on user are assumed.

The following code snippet illustrates how to create an instance of a Connection object using VBScript.
code:
1
2
Set con = CreateObject("ADODB.Connection")
con.Provider = "ADsDSOObject"

The next example is an equivalent Active Server Page (ASP) code snippet.
code:
1
2
3
4
<%
Set con = Server.CreateObject("ADODB.Connection")
con.Provider = "ADsDSOObject"
%>

Here is the same example in Visual Basic. Note that you must include the ADO type library (msadoXX.dll) as one of the references in the Visual Basic project.
code:
1
2
Dim Con As New Connection
con.Provider = "ADsDSOObject"

You can specify user authentication data by setting the properties of the Connection object. The user-authentication properties supported by ADSI are listed in the following table.
code:
1
2
3
4
5
Property: Description 
"User ID" A string that identifies the user whose security context is used when performing the search. For information about the format of the user name string, see the discussion of the user name parameter in the IADsOpenDSObject::OpenDSObject method. If not specified, the default is the logged on user (or the user being impersonated by the calling process). 
"Password" A string that specifies the password of the user identified by "User ID". 
"Encrypt Password" A Boolean value that specifies whether the password is encrypted. The default is False. 
"ADSI Flag" A set of flags from the ADS_AUTHENTICATION_ENUM enumeration that specify the binding authentication options. The default is zero.

This example shows how the properties are set before creating the Command object.
code:
1
2
3
4
5
6
Set oConnect = CreateObject("ADODB.Connection")
oConnect.Provider = "ADsDSOObject"
oConnect.Properties("User ID") = stUser
oConnect.Properties("Password") = stPass
oConnect.Properties("Encrypt Password") = True
oConnect.Open "DS Query", stUser, stPass


The second ADO object is the Command object. The ProgID is "ADODB.Command". This object lets you issue query statements and other commands to ADSI using the active connection. The Command object uses its ActiveConnection property to maintain an active connection. It also maintains the CommandText property to hold query statements issued by a user. The query statements are expressed in either the SQL dialect or the LDAP dialect. The following code snippets illustrate how to create a Command object.

VBScript example:
code:
1
2
3
4
5
6
7
8
9
10
Set command = CreateObject("ADODB.Command")
Set command.ActiveConnection = oConnect
command.CommandText = 
"SELECT AdsPath, cn FROM 'LDAP://DC=Microsoft,DC=com' WHERE objectClass = '*'"
Visual Basic example: Note you must include ADO type library (msadoXX.dll) as one of the references.

Dim command As New Command
Set command.ActiveConnection = oConnect
command.CommandText = 
    "<LDAP://DC=Microsoft,DC=com>;(objectClass=*);AdsPath, cn; subTree"

You can specify search options by setting the property of the Command object actually called Property. Acceptable properties are listed in the following table.
code:
1
2
3
4
5
6
7
8
9
10
11
12
Property: Description 
"Asynchronous" A Boolean value that specifies whether the search is synchronous or asynchronous. The default is False (synchronous). A synchronous search blocks until the server returns the entire result (or for a paged search, the entire page). An asynchronous search blocks until one row of the search results is available, or until the time specified by the "Timeout" property elapses. 
"Cache results" A Boolean value that specifies whether the result should be cached on the client side. The default is True; ADSI caches the result set. Turning off this option may be desirable for large result sets. 
"Chase referrals" A value from the ADS_CHASE_REFERRALS_ENUM that specifies how the search chases referrals. The default is ADS_CHASE_REFERRALS_EXTERNAL. 
"Column Names Only" A Boolean value that indicates that the search should retrieve only the name of attributes to which values have been assigned. The default is False. 
"Deref Aliases" A Boolean value that specifies whether aliases of found objects are resolved. The default is False. 
"Page size" An integer value that turns on paging and specifies the maximum number of objects to return in a results set. The default is no page size. For more information, see Paging. 
"SearchScope" A value from the ADS_SCOPEENUM enumeration that specifies the search scope. The default is ADS_SCOPE_SUBTREE. 
"Size Limit" An integer value that specifies the size limit for the search. For Active Directory, the size limit specifies the maximum number of returned objects. The server stops searching once the size limit is reached and returns the results accumulated up to that point. The default is no limit. 
"Sort on" A string that specifies a comma-separated list of attributes to use as sort keys. This property works only for directory servers that support the LDAP control for server-side sorting. Active Directory supports the sort control, but it can impact server performance, particularly if the results set is large. Note that Active Directory supports only a single sort key. The default is no sorting. 
"Time Limit" An integer value that specifies the time limit (in seconds) for the search. When the time limit is reached, the server stops searching and returns the results accumulated to that point. The default is no time limit. 
"Timeout" An integer value that specifies the client-side timeout value (in seconds). This value indicates the time the client waits for results from the server before abandoning the search. The default is no timeout.

The following code example illustrates how to set search options in Visual Basic.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
Dim Com As New Command
 
Com.Properties("Page Size") = 1000
Com.Properties("Timeout") = 30     'seconds
Com.Properties("searchscope") = ADS_SCOPE_ONELEVEL     'Define in ADS_SCOPEENUM
Com.Properties("Chase referrals") = ADS_CHASE_REFERRALS_EXTERNAL
Com.Properties("Cache Results") = False     'do not cache the result set
The third ADO object is RecordSet. You obtain this object when you invoke the Execute method on a Command object. The primary function of the RecordSet object is to enumerate the result set and obtain the data. The result set can contain values for attributes that have both single or multiple values. Getting a single-valued attribute is straightforward, similar to getting the column value in the relational database (for example, Fields('name').Value). Getting an attribute with multiple values, however, is more challenging. In this case, the Field.Value is an array and you must check the lower and upper bound of the array, as illustrated in the following example.

Set rs = Com.Execute
 
For i = 0 To rs.Fields.Count - 1
  Debug.Print rs.Fields(i).Name, rs.Fields(i).Type
Next i
 
'--------------------------
'Navigate the record set.
'--------------------------
rs.MoveFirst
lstResult.Clear 'Clear the user interface.
While Not rs.EOF
For i = 0 To rs.Fields.Count - 1
    'For Multi Value attribute
    If rs.Fields(i).Type = adVariant And Not (IsNull(rs.Fields(i).Value)) Then
      Debug.Print rs.Fields(i).Name, " = "
      For j = LBound(rs.Fields(i).Value) To UBound(rs.Fields(i).Value)
        Debug.Print rs.Fields(i).Value(j), " # "
        lstResult.AddItem rs.Fields(i).Value(j)
      Next j
    Else
      'For Single Value attribute.
       Debug.Print rs.Fields(i).Name, " = ", rs.Fields(i).Value
       lstResult.AddItem rs.Fields(i).Value
    End If
Next i
rs.MoveNext
Wend

The following example disables the user accounts on an LDAP server using Visual Basic.
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Dim X as IADs
Dim con As New Connection, rs As New Recordset
Dim MyUser As IADsUser
 
con.Provider = "ADsDSOObject"
con.Open "Active Directory Provider", "CN=Foobar,CN=Users,DC=MICROSOFT,DC=COM,O=INTERNET", "Password"
Set rs = con.Execute("<LDAP://MyMachine/DC=MyDomain,DC=Microsoft,DC=com>;(objectClass=User);ADsPath;onelevel")
 
While Not rs.EOF
    ' Bind to the object to make changes 
    ' to it since ADO is currently read-only.
    MyUser = GetObject(rs.Fields(0).Value)
    MyUser.AccountDisabled = True
    rs.MoveNext
Wend

For more information about the ADO object model, see ActiveX Data Objects.

Microsoft Platform SDK, February 2001 Edition.
This content last built on Thursday, February 01, 2001.

Verwijderd

Topicstarter
thanks voor alle info! Heb zelf ook de local msdn-library en had het ook al gevonden, maar het probleem is dat de bovenstaande code volgens mij goed is (ook als ik naar deze info kijk) en dat het niet werkt en ik niet precies weet waarom...

Misschien zie ik iets over het hoofd, maar heb er al een paar keer doorheen gelezen en van alles geprobeerd zonder resultaat...

m.a.w: Waarom deze foutmelding?

  • mulder
  • Registratie: Augustus 2001
  • Laatst online: 15:41

mulder

ik spuug op het trottoir

BTW, ben je local bezig, ben je zelf de server? Ik heb hier een tijd terug ook mee gewerkt, en viel mij ook op dat als ik vanaf mijn eigen machine, naar mijn eigen machine ging het een stuk trager was.

oogjes open, snaveltjes dicht


Verwijderd

Topicstarter
nee, de nt-server is een andere server... De reden waarom het zo traag is is hoogstwaarschijnlijk dat het domein (ITH) een domein is dat over meerdere locaties strekt (in dit geval van Kaapstad tot Johannesburg :o)

Het probleem is dat dit niet 123 veranderd kan worden (op dit moment)...Er wordt pas ergens volgend jaar overgestapt op windows2000 en LDAP/Active Directory

Verwijderd

ADSI doet volgens mij ook iets met caching. Kun je daar niet iets mee (vraag mij niets, want zoveel weet ik ook meer :))

Verwijderd

Topicstarter
Hmm..had een klein stom foutje over het hoofd gezien ('-je vergeten in de query :o) Maar nu krijg ik een andere foutmelding:

Error Type:
Provider (0x80040E37)
Table does not exist.


:?

Verwijderd

Hoe ziet je query er nu dan uit?

Verwijderd

Topicstarter
Op woensdag 19 december 2001 23:43 schreef Doekman het volgende:
Hoe ziet je query er nu dan uit?
code:
1
2
3
4
5
6
7
set oConnect = CreateObject("ADODB.Connection")
oConnect.Provider = "ADsDSOObject"
oConnect.Open "ADs Provider"
set command = CreateObject("ADODB.Command")
set command.ActiveConnection = oConnect
command.CommandText = "SELECT AdsPath, fullName FROM 'WinNT://ITH/CPTEmployees' WHERE objectClass = 'Members'"
set rs = command.execute

Let op '-je voor WinNT

Verwijderd

Topicstarter
ka..........*BUMP*

Verwijderd

Topicstarter
niemand die me hier uit de brand kan helpen?

Verwijderd

Ik gebruik altijd de LDAP syntax voor een query. Zou zoiets moeten worden:
code:
1
command.CommandText = "<serverNaam\ou=CPTEmployees,o=ITH>;(objectClass=Members);adspath,fullName;subtree"

Ik weet niet of de syntax precies zo is. Ik hoop dat het werkt.

Verwijderd

Topicstarter
thanks, maar zelfde fout :?
code:
1
2
3
4
5
6
7
8
set oConnect = CreateObject("ADODB.Connection")
oConnect.Provider = "ADsDSOObject"
oConnect.Open "ADs Provider"

set command = CreateObject("ADODB.Command")
set command.ActiveConnection = oConnect
command.CommandText = "<serverNaam\ou=CPTEmployees,o=ITH>;(objectClass=Members);adspath,fullName;subtree"
set rs = command.execute

  • _JGC_
  • Registratie: Juli 2000
  • Laatst online: 20:30
Ben zelf niet helemaal bekend met ASP en ADSI, etc, maar met MySQL zet je nooit '' om je table, maar backquotes: ``, misschien dat een oplossing?
Pagina: 1