Re: What's wrong with my code?
- From: "Roger" <r_d_h1@xxxxxxxxx>
- Date: Tue, 3 Jan 2006 13:06:33 -0600
Yes indeed. That's all it was. Thanks Richard. You are the man!!!
"Richard Mueller" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:%23Ep7JTJEGHA.1816@xxxxxxxxxxxxxxxxxxxxxxx
> Roger wrote:
>
>>I get this error message when it tries to insert data into the 'Printers'
>>table.
>>
>> ADODB.Recordset: Either BOF or EOF is True, or the current record has
>> been deleted. Requested operation requires a current record.
>>
>> ******************Start of code************************
>> ' Constants for DB connection
>> Const DB_CONNECT_STRING = "Provider=SQLOLEDB.1;Data Source=URBSQL01;
>> Initial Catalog=Test; Integrated Security=SSPI;"
>> Const adOpenStatic = 3
>> Const adLockOptimistic = 3
>> Const adUseClient = 3
>>
>> 'On Error Resume Next
>>
>> strComputer = "."
>>
>> Set objConnection = CreateObject("ADODB.Connection")
>> Set objRecordset = CreateObject("ADODB.Recordset")
>>
>> objConnection.Open DB_CONNECT_STRING
>> objRecordset.CursorLocation = adUseClient
>>
>> objRecordset.Open "SELECT * FROM Hardware" , objConnection, _
>> adOpenStatic, adLockOptimistic
>>
>> Set objWMIService = GetObject("winmgmts:" _
>> & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>>
>> Set colOSes = objWMIService.ExecQuery("Select * from
>> Win32_OperatingSystem")
>> For Each objOS in colOSes
>> strCname = objOS.CSName
>> Wscript.Echo "Computer Name: " & objOS.CSName
>> Wscript.Echo "Version: " & objOS.Version 'Version & build
>> Wscript.Echo "Build Number: " & objOS.BuildNumber 'Build
>> WScript.Echo "Service Pack: " & objOS.ServicePackMajorVersion & "." &
>> _
>> objOS.ServicePackMinorVersion
>>
>> ' Add Records to SQL DB Table called Hardware
>> objRecordset.AddNew
>> objRecordset("ComputerName") = objOS.CSName
>> objRecordset("Version") = objOS.Version
>> objRecordset("BuildNumber") = objOS.BuildNumber
>> objRecordset("ServicePack") = objOS.ServicePackMajorVersion & "." & _
>> objOS.ServicePackMinorVersion
>> Next
>>
>> Set colCompItems = objWMIService.ExecQuery("SELECT * FROM
>> Win32_ComputerSystem", "WQL", _
>> wbemFlagReturnImmediately + wbemFlagForwardOnly)
>>
>> For Each objItem In colCompItems
>> WScript.Echo "Name: " & objItem.Name
>> WScript.Echo "TotalPhysicalMemory: " & objItem.TotalPhysicalMemory
>> WScript.Echo "UserName: " & objItem.UserName
>>
>> objRecordset("Name") = objItem.Name
>> objRecordset("TotalPhysicalMemory") = objItem.TotalPhysicalMemory
>> objRecordset("UserName") = objItem.UserName
>> strUserName = objItem.UserName
>> objRecordset.Update
>> objRecordset.Close
>> Next
>>
>>
>>
>> objRecordset.Open "SELECT * FROM Printers" , objConnection, _
>> adOpenStatic, adLockOptimistic
>>
>>
>> Set colPrtItems = objWMIService.ExecQuery("SELECT * FROM Win32_Printer",
>> "WQL", _
>> wbemFlagReturnImmediately + wbemFlagForwardOnly)
>>
>> For Each objItem In colPrtItems
>> WScript.Echo "UserName: " & strUsername
>> WScript.Echo "Default: " & objItem.Default
>> WScript.Echo "DeviceID: " & objItem.DeviceID
>> WScript.Echo "Name: " & objItem.Name
>> WScript.Echo "PortName: " & objItem.PortName
>> WScript.Echo "SeparatorFile: " & objItem.SeparatorFile
>> WScript.Echo "ServerName: " & objItem.ServerName
>> WScript.Echo "ShareName: " & objItem.ShareName
>> objRecordset("UserName") = strUserName
>> objRecordset("PrinterName") = objItem.Name
>> objRecordset("PortName") = objItem.PortName
>> objRecordset("SeparatorFile") = objItem.SeparatorFile
>> objRecordset.Update
>> Next
>>
>> objRecordset.Close
>> objConnection.Close
>
> Hi,
>
> Don't you need to invoke the AddNew method before assigning values to
> fields in the Printers table? Also, your code assumes there is but one OS
> and one computer System (reasonable).
>
> --
> Richard
> Microsoft MVP Scripting and ADSI
> Hilltop Lab - http://www.rlmueller.net
>
.
- References:
- What's wrong with my code?
- From: Roger
- Re: What's wrong with my code?
- From: Richard Mueller
- What's wrong with my code?
- Prev by Date: Re: What's wrong with my code?
- Next by Date: Re: User Profiles
- Previous by thread: Re: What's wrong with my code?
- Next by thread: newbie help!
- Index(es):
Relevant Pages
|