View Full Version : vbscript: objRecordset return NULL value

04-27-2009, 10:04 AM
First of all, I'm sorry if I'm in the wrong group of discussion. I couldn't find discussion forum for vbscript.

The problem I had is in vbscript coding.

The coding is as below:
Const adOpenStatic = 3
Const adLockOptimistic = 3
Const adUseClient = 3

strDNSServer = WScript.Arguments(0)
strDomainName = WScript.Arguments(1)

Dim ConnString : ConnString = "PROVIDER=SQLOLEDB;SERVER=CYDEV;DATABASE=report;UID=vbscript;PWD=vbscript"

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strDNSServer & "\root\MicrosoftDNS")

Set colItems = objWMIService.ExecQuery("Select * from MicrosoftDNS_AType")

objConnection.Open ConnString
objRecordset.CursorLocation = adUseClient
objRecordset.Open _
"SELECT [HostEntry], [Zone], [IPAddress], [ServerName], [Requestor], [DateModified], [Notes], [DNSState]" _
&" FROM [report].[dbo].[DNS] WHERE [Zone] = '" & strDomainName & "'", objConnection, adOpenStatic, adLockOptimistic

Dim currDate : currDate = YEAR(Date()) & "-" & customDate(Month(date()),2) & "-" & customDate(DAY(date()),2)

'Wscript.Echo strDNSServer
'WScript.Echo strDomainName

'On Error Resume Next

For Each objItem in colItems
Dim tmpSplit : tmpSplit = Split(ObjItem.OwnerName,".")
strSearchHost = "[HostEntry] = '" & tmpSplit(0) & "'"
objRecordset.Find strSearchHost
Wscript.Echo tmpSplit(0)
Wscript.Echo "test: " & objRecordset("HostEntry")
'Wscript.Echo objRecordset("Zone")
'Do While Not objRecordset.EOF
If objRecordset.EOF Then
Wscript.Echo "Record not found"
ElseIf (tmpSplit(0) = RTrim(objRecordset("HostEntry"))) Then
'objRecordset("IPAddress") = objItem.IPAddress
'objRecordset("DateModified") = currDate
Wscript.Echo "IP Address: " & objItem.IPAddress
Wscript.Echo "Owner Name: " & objItem.OwnerName
Wscript.Echo "Container Name: " & objItem.ContainerName
Wscript.Echo "current Date : " & currDate
Wscript.Echo "Domain Name: " & objItem.DomainName
Wscript.Echo "Text Representation: " & objItem.TextRepresentation
End If


Function customDate(n, totalDigits)
If totalDigits > len(n) Then
customDate = String(totalDigits-len(n),"0") & n
customDate = n
End If
End Function
What the code does is that, it will take 2 arguments. the first argument is the DNS Server, and the 2nd argument is the domain name.
Then it will use ADODB to connect with the database where the data for existing DNS inventory is stored.
The problem that I'm facing is that, whenever I try to display the recordset, it keep looping in objRecordset.EOF. any idea where might be wrong?

Thanks in advance.

Old Pedant
04-28-2009, 12:10 AM
You have the MoveNext *AFTER* the LOOP statement. Reverse their order.

There isn't any forum here for VBScript, let alone for VBS in WSH. This site *tends* to not be Windows-oriented, though they do have the ASP and ASP.NET forums. You might try http://p2p.wrox.com where they do have at least one VBS forum that does get some posters using WSH.

As an alternative, post VBS questions in the ASP forum here. After all, the language is the same; just the "host" (WSH vs. ASP platforms) differs.