Re: What's wrong with my code?



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
>


.



Relevant Pages

  • Re: Whats wrong with my code?
    ... >I get this error message when it tries to insert data into the 'Printers' ... > Const adLockOptimistic = 3 ... > For Each objItem In colCompItems ...
    (microsoft.public.scripting.vbscript)
  • Whats wrong with my code?
    ... I get this error message when it tries to insert data into the 'Printers' ... Const adLockOptimistic = 3 ... For Each objItem In colCompItems ... objRecordset= strUserName ...
    (microsoft.public.scripting.vbscript)
  • Re: String corrupted after throw
    ... > didn't realise it does not have automatic storage but instead exists ... > the exception to be included in the error message. ... > const references to it. ...
    (comp.lang.cpp)
  • Re: w2k unjoin old / join new domain trouble
    ... I'm not sure why you're seeing that error message - it surely is not the ... Richard G. Harper rgharper@xxxxxxxxx ... installed service" so I´m back to square one. ... critical website (the contents that is, databases and a whole lot of ...
    (microsoft.public.win2000.networking)
  • Re: [Error number: 0xC80003FA]
    ... that is the only "fix" that has worked for that particular error message. ... > to SDOLD it just made a new file duplicate name; SoftwareDistribution was ... >> Hi Richard, ...
    (microsoft.public.windowsupdate)

Quantcast