ridzz
04-27-2009, 09: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
'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.
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.