Skip to content

LDAP Query from Foxpro

Needing LDAP access to be able to create some sort of Single Sign-On (SSO), I googled and created this testcode that is able to query the LDAP and place the results in a cursor.

This is the complete code, you just have to replace 3 important parameters: identified by the < > characters.

* Query LDAP from Foxpro
* Connecting:
* Adodb to cursor:

Local loConnection As Adodb.Connection, loRecordSet As Adodb.Recordset

loConnection = Createobject('Adodb.Connection')
loConnection.Provider = "ADsDSOObject"
loConnection.Properties('User ID') = "<service user name>"
loConnection.Properties('Password') = "<service user password>"
loConnection.Properties('Encrypt Password') = .F.
loConnection.Open("Active Directory Provider")

lcServer = 'LDAP://<server>' 

loRecordSet = loConnection.Execute([SELECT adsPath,displayName,givenName,sn, distinguishedName, userPrincipalName, sAmAccountName FROM ']+lcServer+[']+;
	[Where objectClass = 'user' And objectCategory='Person'])

loCursor = CREATEOBJECT([CursorAdapter])
loCursor.Alias = [crLdap] && cursor Alias
loCursor.DataSourceType = [ADO] 
loCursor.CursorFill(,,,loRecordSet) && fill corsor
loCursor.CursorDetach() && Detach cursor so it still be open after CursorAdapter is destroyed
loCursor = NULL


Leave a Reply

Your email address will not be published. Required fields are marked *