Solved

VBscript end of record set not finishing

Posted on 2014-01-16
4
476 Views
Last Modified: 2014-01-22
I’m not sure if this will make any sense.. but
 I’m making an VBscript that connects to Active Directory and then imports the records  into Sql.

The Record set is not looping all the way to the end.  It see all the records (+8000) in the logs but is doesn't make it pass 5000 records when writing to SQL or passed 7000 records when just writing to a TXT file instead of sql.

Any ideas?

Some of the code....
* the script does echo out the right number of records in AD.
Sub GetAttribs
	intCount = 1
	objCommand.CommandText = FormatLDAPString (UserOUString, "user", strFilter, strFields)
'WScript.Echo "Executing Query..."

	Set objRS = objCommand.Execute
'WScript.Echo "Records found:   " & objRS.RecordCount
'================================================================
	With objRS
		.MoveFirst
		Do Until .EOF
			strADUsername          = .Fields("sAMAccountName").Value
			‘more items listed if full script (23 total)
'===========================================
'Step: Write to SQL or Txt
'===========================================
' .......
'===========================================
'Step: End Loops
'===========================================
			intCount = intCount + 1
		    .MoveNext
		Loop
	End With
	objRS.Close

Open in new window

0
Comment
Question by:POOK-101
  • 2
  • 2
4 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 250 total points
Comment Utility
This is more often a result of the .PageSize property in the LDAP query.  It should be set to 1000 to allow more records to be returned.

As a simple test, can you just do this:
intRecord = 0
While Not objRS.EOF
   intRecord = intRecord + 1
   WScript.Echo intRecord
   objRS.MoveNext
Wend

Open in new window


and see the record count.

Regards,

Rob.
0
 

Assisted Solution

by:POOK-101
POOK-101 earned 0 total points
Comment Utility
So i'm not sure why, but when i  hide the WScript.Echo command and the script finished with out problems. (all 8000 plus records)  I had about 15 different echo commands in the script.
Also i ran the script outside my VBS editor. (PrimalScipt)

How i hide the commands, so i can turn them back on if needed.

If iDebugMode = 1 Then WScript.Echo "Processing DB Functions Now"

Open in new window


Not sure why this worked.
0
 
LVL 65

Expert Comment

by:RobSampson
Comment Utility
Not sure. If it was running under WScript, or was somehow hidden, maybe you couldn't see the echos. Glad it works anyway.
0
 

Author Closing Comment

by:POOK-101
Comment Utility
I found the fix, but the reply gave me an idea of what to try.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now