Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - ADODB.Connection Problem. Need help troubleshooting.

Reply
 
Old 08-23-2009   #1 (permalink)
Dave


 
 

ADODB.Connection Problem. Need help troubleshooting.

Hi, I wrote a script the other day at work that connects to a remote machine
and gets the logged on user. Next it searches AD for the ADSPath. Finally I
bind to the user account and return the user's name. This has worked great on
every machine I've tried it on with the exception of one. I have narrowed the
problem down to the machine. The owner of the machine cannot run it and if I
log into his machine I get the same errror, but yet the same script works on
every other machine.

If I use the following it works fine which is showing the machine has rights
and can connect to the AD.

Set objUser = GetObject _
("LDAP://cn=examplename,ou=someou,dc=ourdomain,dc=com")
Wscript.Echo "First Name: " & objUser.displayname

If I use this method it fails. I don't have the code with me, but hopefully
you see what I'm trying to say.

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objCommand.ActiveConnection = objConnection


I'm wondering if the machine is missing something to be able to use
ADODB.Connection. If I had a fresh XP machine and I used a script to connect
to the AD provider would it work or do you need something special installed
to connect? Any help would be appreciated.

My System SpecsSystem Spec
Old 08-24-2009   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: ADODB.Connection Problem. Need help troubleshooting.


"Dave" <Dave@xxxxxx> wrote in message
news:1DD3D162-5F69-46E3-A017-48223B68F978@xxxxxx
Quote:

> Hi, I wrote a script the other day at work that connects to a remote
> machine
> and gets the logged on user. Next it searches AD for the ADSPath. Finally
> I
> bind to the user account and return the user's name. This has worked great
> on
> every machine I've tried it on with the exception of one. I have narrowed
> the
> problem down to the machine. The owner of the machine cannot run it and if
> I
> log into his machine I get the same errror, but yet the same script works
> on
> every other machine.
>
> If I use the following it works fine which is showing the machine has
> rights
> and can connect to the AD.
>
> Set objUser = GetObject _
> ("LDAP://cn=examplename,ou=someou,dc=ourdomain,dc=com")
> Wscript.Echo "First Name: " & objUser.displayname
>
> If I use this method it fails. I don't have the code with me, but
> hopefully
> you see what I'm trying to say.
>
> Set objConnection = CreateObject("ADODB.Connection")
> Set objCommand = CreateObject("ADODB.Command")
> objConnection.Provider = "ADsDSOObject"
> objConnection.Open "Active Directory Provider"
> objCommand.ActiveConnection = objConnection
>
>
> I'm wondering if the machine is missing something to be able to use
> ADODB.Connection. If I had a fresh XP machine and I used a script to
> connect
> to the AD provider would it work or do you need something special
> installed
> to connect? Any help would be appreciated.
You don't say what the error message is, or which line of the script raises
the error. ADO can be used on any computer with MDAC installed. MDAC has
come with every OS since Windows 2000. MDAC is installed on Windows 95/98
and NT when you install DSClient. It seems unlikely the problem computer
does not support ADO. Also, I'm not aware of anything that would require a
newer version of MDAC. You also don't say what OS is on the problem
computer, or if anything is different about it. We will need to see more
code and the error message (and the line the raises the error) to help more.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 08-24-2009   #3 (permalink)
Dave


 
 

Re: ADODB.Connection Problem. Need help troubleshooting.

Thanks for the reply Richard. The machine that is having the problem is a
Windows XP with SP2. The code is converted from VB to autoit, but you get the
gist.

$name is the name passed to this function which is just the user's account
name.

;----------------------------------------

$objConnection = ObjCreate("ADODB.Connection")
$objCommand = ObjCreate("ADODB.Command")
$objConnection.Provider = ("ADsDSOObject")
$objConnection.Open("Active Directory Provider")
$objCommand.ActiveConnection = $objConnection

$objCommand.Properties("Page Size") = 1000
$objCommand.Properties("Searchscope") = 2

$objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://dc=mydomain,dc=com' WHERE objectCategory='user'
" & _ "AND name=" & "'" & $name & "'"
if IsObj($objCommand) Then
MsgBox(0,"", "is object") <-- returns that it is an object
Else
MsgBox(0,"", "not object")
EndIf

$objRecordSet = $objCommand.Execute
$objRecordSet.MoveFirst
;*************************************
MsgBox(0,"", "11e") ;<------ Makes it here
$value = $objRecordSet.Fields("ADsPath").Value <--- Error
MsgBox(0,"", "11f") <--- Never reaches this
;*************************************

$objConnection.Close


---------------------------------------------------------

I tried a few more machines today without problem except for the one machine
I'm writing about. Any ideas?
My System SpecsSystem Spec
Old 08-24-2009   #4 (permalink)
Paul Randall


 
 

Re: ADODB.Connection Problem. Need help troubleshooting.


"Dave" <Dave@xxxxxx> wrote in message
news:035F726D-D90B-4D76-A860-DB40980E556A@xxxxxx
Quote:

> Thanks for the reply Richard. The machine that is having the problem is a
> Windows XP with SP2. The code is converted from VB to autoit, but you get
> the
> gist.
>
> $name is the name passed to this function which is just the user's account
> name.
>
> ;----------------------------------------
>
> $objConnection = ObjCreate("ADODB.Connection")
> $objCommand = ObjCreate("ADODB.Command")
> $objConnection.Provider = ("ADsDSOObject")
> $objConnection.Open("Active Directory Provider")
> $objCommand.ActiveConnection = $objConnection
>
> $objCommand.Properties("Page Size") = 1000
> $objCommand.Properties("Searchscope") = 2
>
> $objCommand.CommandText = _
> "SELECT ADsPath FROM 'LDAP://dc=mydomain,dc=com' WHERE
> objectCategory='user'
> " & _ "AND name=" & "'" & $name & "'"
> if IsObj($objCommand) Then
> MsgBox(0,"", "is object") <-- returns that it is an object
> Else
> MsgBox(0,"", "not object")
> EndIf
>
> $objRecordSet = $objCommand.Execute
> $objRecordSet.MoveFirst
> ;*************************************
> MsgBox(0,"", "11e") ;<------ Makes it here
> $value = $objRecordSet.Fields("ADsPath").Value <--- Error
> MsgBox(0,"", "11f") <--- Never reaches this
> ;*************************************
>
> $objConnection.Close
>
>
> ---------------------------------------------------------
>
> I tried a few more machines today without problem except for the one
> machine
> I'm writing about. Any ideas?
Are you saying that the code was originally VB, and was converted to AutoIt,
and you want help with "it doesn't work", and you think a VBScript
(different from VB and AutoIt) newsgroup is a good place to ask?

Maybe you should convert the relevant section of code to VBScript, get it
working on the machines where your AutoIt code works, and then try it on the
non-working machine and report the complete error message. That would
convey way more info than "it doesn't work" and we would have more knowledge
of your code than "you get the gist".

-Paul Randall


My System SpecsSystem Spec
Old 08-24-2009   #5 (permalink)
Dave


 
 

Re: ADODB.Connection Problem. Need help troubleshooting.

> Are you saying that the code was originally VB, and was converted to
AutoIt,
Quote:

> and you want help with "it doesn't work", and you think a VBScript
> (different from VB and AutoIt) newsgroup is a good place to ask?
>
> Maybe you should convert the relevant section of code to VBScript, get it
> working on the machines where your AutoIt code works, and then try it on the
> non-working machine and report the complete error message. That would
> convey way more info than "it doesn't work" and we would have more knowledge
> of your code than "you get the gist".
I didn't mean to offend. It was stupid of me to ask about another language.
Sorry about that.

Here is the code converted back to VB.

---------------------------------------------------------------------------------

username = "myname"

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = ("ADsDSOObject")
objConnection.Open("Active Directory Provider")
objCommand.ActiveConnection = ObjConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = 2

objCommand.CommandText = _
"SELECT ADsPath FROM 'LDAP://dc=mydomain,dc=com' WHERE " & _
"objectCategory='user'" & _
"AND name='" & username & "'"

Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Wscript.Echo objRecordSet.Fields("ADsPath").Value

objConnection.Close

---------------------------------------------------------------------------------

This VB script works fine on my machine, but again it doesn't work on my
co-workers. I receive the following error:

Line: 6
Char: 1
Error: Provider cannot be found. It may not be installed properly
Code: 800A0E7A
Source: ADODB.Connection

The machine is running the same exact version of MDAC as I am. Again the
machine is a Windows XP SP2 32 bit. Any help would be appreciated.


My System SpecsSystem Spec
Old 08-24-2009   #6 (permalink)
Dave


 
 

Re: ADODB.Connection Problem. Need help troubleshooting.

Well converting the file back to VB gave me the error I needed to resolve the
issue. Re-installing MDAC fixed the issue. Thanks for the help guys.
My System SpecsSystem Spec
Old 08-24-2009   #7 (permalink)
Paul Randall


 
 

Re: ADODB.Connection Problem. Need help troubleshooting.


"Dave" <Dave@xxxxxx> wrote in message
news:AF901C00-D6E3-4A56-A5B8-2FAE9CD4423E@xxxxxx
Quote:

> Well converting the file back to VB gave me the error I needed to resolve
> the
> issue. Re-installing MDAC fixed the issue. Thanks for the help guys.
Thanks for letting us know you got it fixed.
I often find that doing the work to give people the info needed to help me,
soon leads me to the solution.

-Paul Randall


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Using SUM with ADODB object VB Script
Using ADODB VB Script
Troubleshooting Internet Connection Vista networking & sharing
ADODB: com and .net PowerShell
Powershell 32 vs. 64 when using ADODB PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

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 38 39 40 41 42 43 44 45 46