Solved

VBscript end of record set not finishing

Posted on 2014-01-16
4
477 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
ID: 39787274
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
ID: 39789193
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
ID: 39790571
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
ID: 39799476
I found the fix, but the reply gave me an idea of what to try.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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…

929 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

11 Experts available now in Live!

Get 1:1 Help Now