Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    vbscript: objRecordset return NULL value

    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

    'objRecordSet.MoveFirst
    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
    'objRecordset.Update
    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
    Wscript.Echo
    End If

    'Loop
    'objRecordset.MoveNext
    Next
    objRecordset.Close
    objConnection.Close

    Function customDate(n, totalDigits)
    If totalDigits > len(n) Then
    customDate = String(totalDigits-len(n),"0") & n
    Else
    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.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •