Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query AD multiple times

Status
Not open for further replies.

tvbruwae

Programmer
Aug 9, 2001
224
EU
Hi

I need to run several LDAP queries on two Active Directory environments. I'm using ADODB to do this:

Code:
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText = "SELECT adspath FROM 'LDAP://dc=mydomain,dc=com' WHERE objectCategory='user' AND sAMaccountname='MyAccount'"
Set objMyRecordSet = objCommand.Execute

My question: if I want to run a second, third, .. query, can I just redefine the objCommand.CommandText and execute it into a new recordset? Or will I lose data from the first query when doing so?

The queries will compare object properties between 2 AD's, so it is important to retain the results from each query.
 
>My question: if I want to run a second, third, .. query, can I just redefine the objCommand.CommandText and execute it into a new recordset? Or will I lose data from the first query when doing so?
objMyRecordSet so returned is locally cached. You can set up another recordset by a new reference to the new memory block, that's all you need to do.
[tt]
objCommand.CommandText = "SELECT adspath FROM 'LDAP://dc=mydomain,dc=com' WHERE objectCategory='user' AND sAMaccountname='MyAccount'"
Set objMyRecordSet = objCommand.Execute

objCommand.CommandText = "SELECT adspath FROM 'LDAP://dc=mydomain,dc=com' WHERE objectCategory='user' AND sAMaccountname='MyAccount[highlight]2[/highlight]'"
Set objMyRecordSet[highlight]2[/highlight] = objCommand.Execute
[/tt]
 
Thanks for the fast response! This is the confirmation I was looking for, I couldn't really find a sample script using the same objects in multiple queries.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top