Using an ActiveX Data Object to Bind to ADSI Providers

Since ADSI is also an OLE DB provider, you can use an ActiveX Data Object (ADO) to connect to ADSI providers. As with other ADO providers, to connect to an OLE DB provider, you must create a new connection object and, optionally, specify the credentials. The name of the ADSI OLE DB provider is ADsDSOObject.

For example:

Dim con As New Connection 
'VBScript use: con = CreateObject("ADODB.Connection")
con.Provider = "ADsDSOObject"
con.Open "YourDescriptionHere"

In the previous example, you are connected on behalf of the current user. To specify different credentials, use connection properties:

con.Provider = "ADsDSOObject"
con.Properties("User ID") = "jeffsmith"
con.Properties("Password") = "guesswhat?"
con.Properties("Encrypt Password") = True
con.Open "YourDescriptionHere"

ADSI OLE DB defines the following connection properties.

Property Data type Default
"User ID" BSTR NULL
"Password" BSTR NULL
"Encrypt Password" BOOLEAN FALSE
"ADSI Flag" Long 0

 

Using OLE DB ADO, you cannot bind to a specific object. You can, however, query a specific object and get a result set back. Only ADSI providers that support IDirectorySearch benefit from having ADO as a programming model.

The ADSI Flag property is used to specify the binding authentication option. This property can be a combination of flags from the ADS_AUTHENTICATION_ENUM enumeration.