Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ADO AD Query fails in JScript but works with VBScript

39 views
Skip to first unread message

AZSTYX

unread,
Oct 23, 2009, 11:56:25 AM10/23/09
to
Hello Folks,
Env: WIN XP PRO or WIN 2003 Server
WSH 5.7/cscript

I have a VBScript to query users from AD that I just converted to
JScript but the JScript version is giving me error "Table does no
t exist.". The very same query and user credetials were used for both
scripts. Anyone have any suggestions?
Please and Thanks!!!
:)

VBScript code:
[code]
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.CommandTimeout = 0
objConnection.ConnectionTimeout = 0
objConnection.Properties("User ID") = strUID
objConnection.Properties("Password") = strPassword
objConnection.Properties("Encrypt Password") = True
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Timeout") = 0
objCommand.Properties("Searchscope") = 2
objCommand.Properties("Cache Results") = True
objCommand.Properties("Page Size") = 1000000
objCommand.CommandTimeout = 0


WScript.Echo "Processing Domain [" & strDomain & "]" & " and binding
to this DC [" & strDCName & "]" & " UID[" & strUID & "]"

'Get user and any info in AD
strCommText = "<LDAP://" & strDCName & "/" & strDomain &">;" & _
"(&(objectCategory=Person)(objectClass=User)(!
(userAccountControl:1.2.840.113556.1.4.803:=2)));" & _

"cn,samAccountname,telephoneNumber,sn,givenName,employeeType,displayName,middleName,streetAddress,"
& _

"physicalDeliveryOfficeName,mail,employeeNumber,fmCostCenter,facsimileTelephoneNumber,fmbusinessunit;Subtree"
' These are the attributes that you want to pull from that user.

WScript.Echo "OK, I am executing this AD Inquiry [" & vbCRLF &
strCommText & "]"
objCommand.CommandText = strCommText
On Error Resume Next 'enable error trapping
Set objRecordSet = objCommand.Execute
If Err.Number <> 0 Then
WScript.Echo "ERROR - Problem with Active Directory Query"
WScript.Echo "Error No:" & Err.Number & " - " & Err.Description
If Err.Description = "Permission denied." Then
WScript.Echo "Check AD UID Credentials!"
End If
WScript.Echo "Aborting Program!!!"
WScript.Quit(1) 'send error code
End If
Err.Clear 'clear error object
On Error GoTo 0 'disable error trapping


[/code]

VBScript Execution:

[code]
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Script Started
Processing Domain [DC=mydomain,DC=com] and binding to this DC [ADRS01]
UID[mydomain\myuser]
OK, I am executing this AD Inquiry [
<LDAP://ADRS01/DC=mydomain,DC=com>;(&(objectCategory=Person)
(objectClass=User)(
!(userAccountControl:
1.2.840.113556.1.4.803:=2)));cn,samAccountname,telephoneNum
ber,sn,givenName,employeeType,displayName,middleName,streetAddress,physicalDeliv
eryOfficeName,mail,employeeNumber,fmCostCenter,facsimileTelephoneNumber,fmbusine
ssunit;Subtree]
Script Completed. Records created [8810]


[/code]


JScript code:
[code]
var objConnection = new ActiveXObject("ADODB.Connection");
objConnection.Provider = "ADsDSOObject";
objConnection.Properties("User ID") = strUID;
objConnection.Properties("Password") = strPassword;
objConnection.Properties("Encrypt Password") = true;
objConnection.Open();
var objCommand = new ActiveXObject("ADODB.Command");
objCommand.ActiveConnection = objConnection;
objCommand.Properties("Timeout") = 0;
objCommand.Properties("Searchscope") = 2;
objCommand.Properties("Cache Results") = true;
objCommand.Properties("Page Size") = 1000000;
objCommand.CommandTimeout = 0;
//Get user and attribute info in AD
var strCommText = "<LDAP://" + strDCName + "/" + strDomain + ">;" +
"(&(objectCategory=Person)(objectClass=User)(!
(userAccountControl:1.2.840.113556.1.4.803:=2)));" +

"cn,samAccountname,telephoneNumber,sn,givenName,employeeType,displayName,middleName,streetAddress,"
+
"physicalDeliveryOfficeName,mail,employeeNumber,fmCostCenter,"
+
"facsimileTelephoneNumber,fmbusinessunit" +
";Subtree";
objCommand.CommandText = strCommText;


WScript.Echo("Processing Domain [" + strDomain + "]" + " and binding
to this Domain Controller [" + strDCName + "] " + "using UID[" +
strUID + "]");
WScript.Echo("OK, I am executing this AD Inquiry [\n" + strCommText +
"\n]");
try {
var objRecordSet = objCommand.Execute;
}
catch(e) {
strMsg = "FATAL - Unable to query AD server [" +
strDCName + "], Aborting run!!! Error[" + e.description +
"] ErrNum[" + e.number + "]\n";
WScript.Echo(strMsg);//debug
WScript.Quit(0); //debug

} //end-catch


[/code]


JScript code execution:

[code]
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation. All rights reserved.

Processing Domain [DC=mydomain,DC=com] and binding to this Domain
Controller [ADRS01] using UID[mydomain\myuser]
OK, I am executing this AD Inquiry [
<LDAP://ADRS01/DC=mydomain,DC=com>;(&(objectCategory=Person)
(objectClass=User)(
!(userAccountControl:
1.2.840.113556.1.4.803:=2)));cn,samAccountname,telephoneNum
ber,sn,givenName,employeeType,displayName,middleName,streetAddress,physicalDeliv
eryOfficeName,mail,employeeNumber,fmCostCenter,facsimileTelephoneNumber,fmbusine
ssunit;Subtree
]
FATAL - Unable to query AD server [ADRS01], Aborting run!!! Error
[Table does not exist.] ErrNum[-2147217865]

[/code]


I have even tried reducing the query:

Processing Domain [DC=MYDOMAIN,DC=COM] and binding to this Domain
Controller [A
DRS01] using UID[MYDOMAIN\myuser]
OK, I am executing this AD Inquiry [
<LDAP://ADRS01/DC=FANNIEMAE,DC=COM>;;sn,givenName;Subtree
]
FATAL - Unable to query AD server [ADRS01], Aborting run!!! Error
[Table does not exist.] ErrNum[-2147217865]

AZSTYX

unread,
Oct 23, 2009, 12:12:42 PM10/23/09
to

Made this change but still get same error message:

var objRecordSet = objCommand.Execute();

Richard Mueller [MVP]

unread,
Oct 23, 2009, 12:20:30 PM10/23/09
to

"AZSTYX" <azs...@yahoo.com> wrote in message
news:997daaed-025d-4220...@j9g2000vbp.googlegroups.com...

I assume you added fmCostCenter and fmBusinessUnit to the schema. I thought
the maximum page size setting allowed was 1000. Does it help if you use
1000? I normally use 100. Note this in not a limit on the number of rows
retrieved, just the number of rows returned per page. Also, no need to set
the Searchscope property since you use Subtree in the query.

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


AZSTYX

unread,
Oct 23, 2009, 1:22:16 PM10/23/09
to
On Oct 23, 11:56 am, AZSTYX <azs...@yahoo.com> wrote:

Made this change but still get same error message:

var objRecordSet = objCommand.Execute();

AZSTYX

unread,
Oct 23, 2009, 1:27:06 PM10/23/09
to
On Oct 23, 12:20 pm, "Richard Mueller [MVP]" <rlmueller-

Hey Richard!
Yes, those attributes are in the schema. The exact same query was used
in my VBScript and it works perfectly so I am lost why this is not
working in JScript.
Good point on serachlevel - yes - you are right and also I reduced by
page size to 1000 - it doesn't seem to give any error.
// objCommand.Properties("Searchscope") = 2;
objCommand.Properties("Page Size") = 1000;

Here's another un with reduced parms - still get same error:

OK, I am executing this AD Inquiry [

<LDAP://ADRS01/DC=MYDOMAIN,DC=COM>;(&(objectCategory=Person)
(objectClass=User)(
!(userAccountControl:1.2.840.113556.1.4.803:=2)));sn,givenName;Subtree

AZSTYX

unread,
Oct 23, 2009, 2:52:59 PM10/23/09
to
On Oct 23, 12:20 pm, "Richard Mueller [MVP]" <rlmueller-
nos...@ameritech.nospam.net> wrote:
> Hilltop Lab -http://www.rlmueller.net
> --

Hey Richard!
Yes, those attributes are in the schema. The exact same query was used
in my VBScript and it works perfectly so I am lost why this is not
working in JScript.
Good point on serachlevel - yes - you are right and also I reduced by
page size to 1000 - it doesn't seem to give any error.
// objCommand.Properties("Searchscope") = 2;
objCommand.Properties("Page Size") = 1000;

Here's another un with reduced parms - still get same error:

OK, I am executing this AD Inquiry [
<LDAP://ADRS01/DC=MYDOMAIN,DC=COM>;(&(objectCategory=Person)
(objectClass=User)(
!(userAccountControl:1.2.840.113556.1.4.803:=2)));sn,givenName;Subtree


]
FATAL - Unable to query AD server [ADRS01], Aborting run!!! Error

AZSTYX

unread,
Oct 23, 2009, 3:37:12 PM10/23/09
to

Thanks for all your suggesitons!!!!!
Well, I'm feeling pretty stupid.......I was collecting my command line
arguments which included strUID and strPassword AFTER I executed the
code for :


var objConnection = new ActiveXObject("ADODB.Connection");
objConnection.Provider = "ADsDSOObject";
objConnection.Properties("User ID") = strUID;
objConnection.Properties("Password") = strPassword;

therefore, strUID and strPassword were NULL.
Ouch, sorry for my bad!!!
Well its working now!
:)
Thanks very much - I do apprecite everybody's comments. The message
"Table does not exist." put me offtrack...if the message was
"Permission Denied" - I would have checked my credentials immediately.
Thanks,
Keith

Jim A.

unread,
Oct 26, 2009, 4:01:02 PM10/26/09
to
Meinolf,

Additionally, Could you please recommend a "Primer" or introductory level
Text (book) on what I should study regarding AD

Regards
Jim

--
Jim A.


"AZSTYX" wrote:

> .
>

0 new messages