I keep getting the Either BOF or EOF is True error on line 74 in the script.
Background: i have a script that runs when loging in to the domain, the scripts runs an inventory of the computer with wmi. And i want these data from the wmi query to be added to a sql database.
The first part in the script that writes with "objRS" works greate. But when it comes to objRS2 i get the EOF error. The data from objRS2 should be inserted in to another table but be linked to the first table. The idea is to get info about computer 1 and be able to se all nic to that computer and also some extra things.
The db looks like this.
db name: inventDB
table for objRS data, name: inventTB
in the table i have columns that correspond to the script for objRS data, i also got a column named compID that is the primary key for that table
table for objRS2 data, name: inventNIC
in the table i have columns that correspond to the script for objRS2 data, i also got a column named compID that is linked to the primary key in table inventTB. (table inventNIC dosent contain a primary key if that mathers?)
The code looks like this.
Background: i have a script that runs when loging in to the domain, the scripts runs an inventory of the computer with wmi. And i want these data from the wmi query to be added to a sql database.
The first part in the script that writes with "objRS" works greate. But when it comes to objRS2 i get the EOF error. The data from objRS2 should be inserted in to another table but be linked to the first table. The idea is to get info about computer 1 and be able to se all nic to that computer and also some extra things.
The db looks like this.
db name: inventDB
table for objRS data, name: inventTB
in the table i have columns that correspond to the script for objRS data, i also got a column named compID that is the primary key for that table
table for objRS2 data, name: inventNIC
in the table i have columns that correspond to the script for objRS2 data, i also got a column named compID that is linked to the primary key in table inventTB. (table inventNIC dosent contain a primary key if that mathers?)
The code looks like this.
Code:
'On Error Resume Next
Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objConn = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
objConn.Open "DSN=inventcon;"
objRS.CursorLocation = 3
objRS.Open "SELECT * FROM inventTB" , objConn, 3, 3
Const HKEY_LOCAL_MACHINE = &H80000002
Const UnInstPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer &"\root\default:StdRegProv")
Set objWMIService = GetObject("winmgmts:\\" & strComputer &"\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
objRS.AddNew
objRS("Caption") = objItem.Caption
objRS("Description") = objItem.Description
objRS("InstallDate") = objItem.InstallDate
objRS("Organization") = objItem.Organization
objRS("OSProductSuite") = objItem.OSProductSuite
objRS("RegisteredUser") = objItem.RegisteredUser
objRS("ServicePackMajorVersion") = objItem.ServicePackMajorVersion
objRS("ServicePackMinorVersion") = objItem.ServicePackMinorVersion
objRS("Version") = objItem.Version
objRS("WindowsDirectory") = objItem.WindowsDirectory
objRS.Update
Next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer &"\root\cimv2")
Set colSMBIOS = objWMIService.ExecQuery ("Select * from Win32_SystemEnclosure")
For Each objSMBIOS in colSMBIOS
objRS("SerialNumber") = objSMBIOS.SerialNumber
objRS.Update
next
Set objWMIService = GetObject("winmgmts:\\" & strComputer &"\root\cimv2")
Set colCOMpn = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
For Each objCOMpn in colCOMpn
objRS("Manufacturer") = objCOMpn.Manufacturer
objRS("Model") = objCOMpn.Model
objRS("UserName") = objCOMpn.UserName
objRS("ComputerName") = strComputer
objRS("Name") = objCOMpn.Name
objRS.Update
next
' *****************************************
' ''' ''' The problem starts here....
' *****************************************
Set objRS2 = CreateObject("ADODB.Recordset")
objRS2.CursorLocation = 3
objRS2.Open "SELECT * FROM inventNIC" , objConn, 3, 3
Set colAdapters = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
n = 1
For Each objAdapter in colAdapters
objRS2("Description") = objAdapter.Description
objRS2("MACAddress") = objAdapter.MACAddress
objRS2("DNSHostName") = objAdapter.DNSHostName
If Not IsNull(objAdapter.IPAddress) Then
For i = 0 To UBound(objAdapter.IPAddress)
objRS2("IPAddress") = objAdapter.IPAddress(i)
Next
End If
If Not IsNull(objAdapter.IPSubnet) Then
For i = 0 To UBound(objAdapter.IPSubnet)
objRS2("IPSubnet") = objAdapter.IPSubnet(i)
Next
End If
If Not IsNull(objAdapter.DefaultIPGateway) Then
For i = 0 To UBound(objAdapter.DefaultIPGateway)
objRS2("DefaultIPGateway") = objAdapter.DefaultIPGateway(i)
Next
End If
If Not IsNull(objAdapter.DNSServerSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSServerSearchOrder)
objRS2("DNSServerSearchOrder") = objAdapter.DNSServerSearchOrder(i)
Next
End If
objRS2("DNSDomain") = objAdapter.DNSDomain(i)
If Not IsNull(objAdapter.DNSDomainSuffixSearchOrder) Then
For i = 0 To UBound(objAdapter.DNSDomainSuffixSearchOrder)
objRS2("DNSDomainSuffixSearchOrder") = objAdapter.DNSDomainSuffixSearchOrder(i)
Next
End If
objRS2("DHCPEnabled") = objAdapter.DHCPEnabled
objRS2("DHCPServer") = objAdapter.DHCPServer
If Not IsNull(objAdapter.DHCPLeaseObtained) Then
utcLeaseObtained = objAdapter.DHCPLeaseObtained & vbCrLf
strLeaseObtained = WMIDateStringToDate(utcLeaseObtained)
Else
strLeaseObtained = ""
End If
objRS2("strLeaseObtained") = objAdapter.strLeaseObtained
If Not IsNull(objAdapter.DHCPLeaseExpires) Then
utcLeaseExpires = objAdapter.DHCPLeaseExpires & vbCrLf
strLeaseExpires = WMIDateStringToDate(utcLeaseExpires)
Else
strLeaseExpires = ""
End If
objRS2("strLeaseExpires") = objAdapter.strLeaseExpires
objRS2("WINSPrimaryServer") = objAdapter.WINSPrimaryServer
objRS2("WINSSecondaryServer") = objAdapter.WINSSecondaryServer
objRS2.Update
n = n + 1
Next
objRS.Close
objRS2.Close
objConn.Close