Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO error in script with variable, fine with specified number 1

Status
Not open for further replies.

billieT

MIS
Dec 11, 2001
107
NZ
Hi there, this one is baffling me.

I'm using a script to create Exchange quotas, which is using ADO to hook into LDAP. When I "hardcode" the quota size, the script works perfectly. When I try to use variables (after getting input defining the quota size variable), the script fails with an "80004005" error - which I just assume something is wrong with the data that we're trying to perform the LDAP function with.

Here are the parts of the script doing stuff:
Code:
'... define variables and const MB=1024

strGrpName= InputBox("Enter the name of the group you wish to set quotas for")
QuotaAmount=InputBox("Enter the quota amount in MB. If nothing is input, the quota will be set to 300MB.")
If QuotaAmount="" Then QuotaAmount=300
WarningAmount = QuotaAmount*0.90
QuotaAmount = QuotaAmount*MB
WarningAmount = WarningAmount*MB

'... open ADODB.Connection 
'... <snipped>

    group.Put "description", "Admin modified via Script"
    group.Put "mDBUseDefaults", "FALSE"
    group.Put "mDBStorageQuota", WarningAmount
    group.Put "mDBOverQuotaLimit", QuotaAmount

'.... etc, close connections

Where the script fails is on the lines that specify group.Put "mDBStorageQuota", WarningAmount and the subsequent line. If the script reads group.Put "mDBStorageQuota", 358400, then it works fine.

Is there some kind of string vs numeric mismatch going on? If so, how does one specify the numeric value?
 
Hello billieT,

I think you have to validate a bit QuotaAmount from the inputbox, for instance, right after it, test isnumeric(quotaAmount). If true, convert it there. If false, loop back for inputbox with a message to user.

regards - tsuji
 
Thanks for the suggestion, tsuji, validation is probably a good idea. But when I'm testing the script, I'm most certainly inputting a numeral.

But I've tried testing for isnumeric, adding a line if true newQuotaAmount = int(QuotaAmount) and using the newQuotaAmount variable, and I'm still getting the same error. So, I'm still stumped...
 
billieT,

Try use putex(). (Should check the document for this if you like which I haven't.)
[tt]
group.PutEx 2, "mDBStorageQuota", WarningAmount
group.SetInfo
group.PutEx 2, "mDBOverQuotaLimit", QuotaAmount
group.SetInfo
[/tt]
- tsuji
 
Further note:

You said too if WarningAmount etc is numeric, it is fine. I believe then Put should be fine too. Only, commit it early and in reverse order.
[tt]
group.Put "mDBOverQuotaLimit", QuotaAmount
group.setinfo
group.Put "mDBStorageQuota", WarningAmount
group.setinfo
[/tt]
- tsuji
 
well, this is interesting now. It's coming up with the same AD 80004005 error if I use PutEx:

Code:
group.PutEx 2, "description", "Admin modified via Script"
	group.SetInfo 
	group.PutEx 2,"mDBUseDefaults", "FALSE"
	group.SetInfo 
	group.PutEx 2,"mDBOverQuotaLimit",QuotaAmount
	group.SetInfo

but the error is appearing with ALL the PutEX lines quoted above (the first two were working using just plain PUT). Is it perhaps something to do with the way I've bound the ADO?

Code:
Selection = "CN=" & strGrpName _ 
   & ",CN=Users,DC=domain,DC=rootdomain,DC=ac,DC=nz"
Set oConnection = CreateObject("ADODB.Connection")
Set oRecordset = CreateObject("ADODB.Recordset")
oConnection.Provider = "ADsDSOObject" 

strQuery ="<LDAP://DC=domain,DC=rootdomain,DC=ac,DC=nz>;" _
& "(&(objectCategory=person) (memberof=" &  Selection  _
	& "));memberof,cn,distinguishedName;subtree"

Set oRecordset = oConnection.Execute(strQuery)
If oRecordset.EOF And oRecordset.BOF Then
Else
While Not oRecordset.EOF
	Set group = GetObject("LDAP://" & (oRecordset.Fields("distinguishedname")))

The first snippet of code above immediately follows this ADO connection and LDAP query (which to be frank, is the part I've found hardest to work out).
 
Aha! I think with your last post, you're onto something. I just tried commenting out everything except only one put statement:

group.Put "mDBOverQuotaLimit", QuotaAmount
group.setinfo

And that worked perfectly. if I immediately follow with the next lines as you suggested above, then it errors on that following line. I might try a wscript.sleep statement and see if a delay helps
 
nope, I don't know what happened up above, the single line isn't working again (and wscript.sleep 250 didn't help)
 
and now the single line works again!!! this is driving me crackers... more of a delay needed to allow the AD to catch up?
 
billie,

Need to slow down a bit, not the script but in reasoning! especially inconsistent running result.

Idea behind for now is checking whether quota and warning are retrieved to cache by default. This can be resolved by checking documentation. Also, you can test echo out its value rather than change the value rightaway. The treatment is slightly different for these cases. No need to rush. It is close.

- tsuji
 
billieT,

[1] Looking at your connect, I think there are problems. Add these lines after .Provider.
[tt]
oConnection.open
wscript.echo oConnection.State 'should show 1 to be successful
[/tt]
If the echo is not adstateopen, then you authenticate with your dn and password.
[tt]
oConnection.open "","yourDN","yourPWD"
wscript.echo oConnection.State
[/tt]
You can spare
[tt] Set oRecordset = CreateObject("ADODB.Recordset")[/tt]
as you are to established it by .execute method.

[2] In your query, eliminate the space between the &(.)(.) part:
[tt] "(&(objectCategory=person[COLOR=red yellow])([/color]memberof=" & Selection & "));memberof,cn,distinguishedName;subtree"[/tt]

- tsuji
 
thanks again for all your input, tsuji.

Still, there are problems.
1/ the script runs if all the values are "hard-coded"
2/ it runs if the group.Put "mDBOverQuotaLimit",QuotaAmount uses the variable, but NOT if the variable amount is changed via input
3/ it does NOT run if the group.Put "mDBStorageQuota", WarningAmount line is inserted (using the variable) whether any other group.Put lines are present or not
4/ it runs if the "mDBOverQuotaLimit" is set by the QuotaAmount variable (not if the variable is modified at input) AND the "mDBStorageQuota" has a numeric amount hardcoded.
5/ the oConnection.state test is always "true" (I'm running the script as domain admin)

Here is the script in its entirety:
Code:
option explicit
Dim oConnection
Dim Selection
Dim oRecordset 
Dim strQuery
Dim strADsPath
Dim strGrpName
Dim Group
Dim QuotaAmount
Dim WarningAmount
Dim List
const MB = 1024

strGrpName= InputBox("Enter the name of the group you wish to set quotas for: ")
QuotaAmount=InputBox("Enter the quota amount in MB. If nothing is input, the quota will be set to 300MB.")
If QuotaAmount="" Then QuotaAmount=350
WarningAmount = QuotaAmount*0.80
QuotaAmount = int(QuotaAmount*MB)
WarningAmount = int(WarningAmount*MB)

Selection = "CN=" & strGrpName &",CN=Users,{domain distinguishedname}"
Set oConnection = CreateObject("ADODB.Connection")
oConnection.Provider = "ADsDSOObject" 
oConnection.Open "ADs Provider"
wscript.echo oConnection.State

strQuery ="<LDAP://{domain distinguishedname}>;(&(objectCategory=person)(memberof=" &  Selection & "));memberof,cn,distinguishedName;subtree"

Set oRecordset = oConnection.Execute(strQuery)
If oRecordset.EOF And oRecordset.BOF Then
Else
While Not oRecordset.EOF
	Set Group = GetObject("LDAP://" & (oRecordset.Fields("distinguishedname")))
	
' Makes the desired changes
	group.Put "mDBUseDefaults", "FALSE"
	group.SetInfo 
	group.Put "mDBStorageQuota",WarningAmount
	group.SetInfo
	group.Put "mDBOverQuotaLimit",QuotaAmount
	group.SetInfo
	
' builds the list statement for the final confirmation
List = List & (oRecordset.Fields("cn")) & vbCrLf
	oRecordset.MoveNext
Wend
End If
'...cleanup, display result
 
billieT,

Hard code working but not via variable, it is defying law of gravity! One measure you can take is to firmly control the data type here:
[tt] group.Put "mDBStorageQuota",clng(WarningAmount)
group.SetInfo
group.Put "mDBOverQuotaLimit",clng(QuotaAmount)
group.SetInfo[/tt]
They are OLE DB Type DBTYPE_UI4, variant subtype long.

- tsuji
 
Yippee!!!!!! :-D that was the answer, tsuji - as soon as we configured the data type, the script worked exactly as expected.

But yes, it was pretty confusing when the hard-coded amount worked and the variable didn't.

Thanks for all your help
 
billieT,

Thanks for the feedback. Really happy you've sort it out.

- tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top