0
votes

Here is my code, I am trying to open a connection to our database and then using ActiveX to return all the data from column in a table and then outputting it to a text document. I'm getting this error.

PullData.vbs(41, 1) ADODB.Recordset: Item cannot be found in the collection corresponding to the requested name or ordinal.

Here is my code, omitting sensitive information:

Const ForReading  = 1
Dim sServer
Dim sLogin
Dim sPwd
Dim sDb

Dim oCn 
Dim oRs 
sServer   = ""
sLogin    = ""
sPwd      = ""
sDb       = ""

Set oCn = CreateObject( "ADODB.Connection" ) ' set oCn to create an object called ADODB.Connection
Set oRs = CreateObject( "ADODB.Recordset"  ) ' set oRs to create an object called ADODB.Recordset

oCn.ConnectionString = "PROVIDER=SQLOLEDB" & _      
                       ";SERVER="   & sServer   & _
                       ";UID="      & sLogin  & _
                       ";PWD="      & sPwd    & _
                       ";DATABASE=" & sDb & " "
                       oCn.ConnectionTimeout=600
                       oCn.open 'Open the connection to the server

strSelString = "select CallID from dbo.CallLog" 'this is the SQL statement that runs a query on the DB

oRs.Open strSelString,oCn 'This opens the record set and has two parameters, strSelString and oCn

If oRs.EOF Then 'If open record set is at the end of file then...
  wscript.echo "There are no records to retrieve; Check that you have the correct record number." 'echo that there is no records to retrieve.
End if

'if there are records then loop through the fields
Do While Not oRs.EOF ' Do while not open record set is not end of file

strfield = ors("Tracker")

if strfield <> "" then 'If strfield doesn't equal "" then
  Set objFileSystem    = WScript.CreateObject("Scripting.FileSystemObject") 'Set objFileSystem to create object Scripting.FileSystemObject
  Set objOutPutFile    = objFileSystem.CreateTextFile("c:\test.txt", True) 'Set objOutPutFile to create object objFileSystem.CreateTextFile  
  strcomputer = oRs 'strcomputer is set to read the line
  wscript.echo strfield  
  objOutPutFile.WriteLine  strfield &"|" 
  objFileSystem.close
  objOutPutFile.close  
end if

oRs.MoveNext
oCn.Close
Loop
1

1 Answers

3
votes

You ask for the CallID column;

"select CallID from dbo.CallLog"

but then try to read something else:

strfield = ors("Tracker")

so either select Tracker or read CallID.

You could also probably create/open the file outside of the loop.