Hi all!

How to connect to the AD from stand-alone computer? I've found the
connection string for OLE DB connection (Provider=ADSDSOObject;User
Id=myUsername;Password=myPassword;), however I cannot query the AD - an error
"A referral was returned from the server" is occured after I try to Execute
the command.

Here is my code:
-----
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADSDSOObject;User
Id=CN=Administrator,CN=Users,DC=cluster,DC=local;Password=Password;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText =
"<LDAP://server.domain.tld/dc=domain,dc=tld>;(sAMAccountName=" & strLogin &
");distinguishedName;subtree"
Set objRecordSet = objCommand.Execute
-----

The same code works on member server.

Can anybody help?

--
R.V.

RE: Connect to AD from stand-alone computer by RadovanVojtek

RadovanVojtek
Fri Sep 07 04:44:00 PDT 2007

Sorry for inconsistency - the distingushed name of domain in connectino
string is correct in script

--
R.V.


"Radovan Vojtek" wrote:

> Hi all!
>
> How to connect to the AD from stand-alone computer? I've found the
> connection string for OLE DB connection (Provider=ADSDSOObject;User
> Id=myUsername;Password=myPassword;), however I cannot query the AD - an error
> "A referral was returned from the server" is occured after I try to Execute
> the command.
>
> Here is my code:
> -----
> Set objConnection = CreateObject("ADODB.Connection")
> objConnection.Open "Provider=ADSDSOObject;User
> Id=CN=Administrator,CN=Users,DC=cluster,DC=local;Password=Password;"
> Set objCommand = CreateObject("ADODB.Command")
> objCommand.ActiveConnection = objConnection
> objCommand.CommandText =
> "<LDAP://server.domain.tld/dc=domain,dc=tld>;(sAMAccountName=" & strLogin &
> ");distinguishedName;subtree"
> Set objRecordSet = objCommand.Execute
> -----
>
> The same code works on member server.
>
> Can anybody help?
>
> --
> R.V.

Re: Connect to AD from stand-alone computer by Richard

Richard
Fri Sep 07 06:12:34 PDT 2007

Radovan Vojtek wrote:

> How to connect to the AD from stand-alone computer? I've found the
> connection string for OLE DB connection (Provider=ADSDSOObject;User
> Id=myUsername;Password=myPassword;), however I cannot query the AD - an
> error
> "A referral was returned from the server" is occured after I try to
> Execute
> the command.
>
> Here is my code:
> -----
> Set objConnection = CreateObject("ADODB.Connection")
> objConnection.Open "Provider=ADSDSOObject;User
> Id=CN=Administrator,CN=Users,DC=cluster,DC=local;Password=Password;"
> Set objCommand = CreateObject("ADODB.Command")
> objCommand.ActiveConnection = objConnection
> objCommand.CommandText =
> "<LDAP://server.domain.tld/dc=domain,dc=tld>;(sAMAccountName=" & strLogin
> &
> ");distinguishedName;subtree"
> Set objRecordSet = objCommand.Execute
> -----
>
> The same code works on member server.
>

The method I have used is in this link:

http://www.rlmueller.net/ADOAltCredentials.htm

If the computer is not joined to the domain, I believe you must use a server
bind, as explained in the link. Does this help?

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



Re: Connect to AD from stand-alone computer by RadovanVojtek

RadovanVojtek
Fri Sep 07 06:22:02 PDT 2007

Hi Richard!

Thank you for your reply! I've just found an mistake in my script and it
works correctly now, however your link works as well!

--
R.V.


"Richard Mueller [MVP]" wrote:

> Radovan Vojtek wrote:
>
> > How to connect to the AD from stand-alone computer? I've found the
> > connection string for OLE DB connection (Provider=ADSDSOObject;User
> > Id=myUsername;Password=myPassword;), however I cannot query the AD - an
> > error
> > "A referral was returned from the server" is occured after I try to
> > Execute
> > the command.
> >
> > Here is my code:
> > -----
> > Set objConnection = CreateObject("ADODB.Connection")
> > objConnection.Open "Provider=ADSDSOObject;User
> > Id=CN=Administrator,CN=Users,DC=cluster,DC=local;Password=Password;"
> > Set objCommand = CreateObject("ADODB.Command")
> > objCommand.ActiveConnection = objConnection
> > objCommand.CommandText =
> > "<LDAP://server.domain.tld/dc=domain,dc=tld>;(sAMAccountName=" & strLogin
> > &
> > ");distinguishedName;subtree"
> > Set objRecordSet = objCommand.Execute
> > -----
> >
> > The same code works on member server.
> >
>
> The method I have used is in this link:
>
> http://www.rlmueller.net/ADOAltCredentials.htm
>
> If the computer is not joined to the domain, I believe you must use a server
> bind, as explained in the link. Does this help?
>
> --
> Richard Mueller
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
> --
>
>
>