简体   繁体   中英

WSF and ADO with DB2 , recordset.MoveNext not supported error in vbscript

I am trying to loop on a recordset returned from db2 using a .wsf file and vbscript .

the vbscript libfile(lib.vbs) is as follows

'***************  
Const ADOCon="Provider=IBMDADB2.1;Password=*****;User ID=*****;Data Source=yourdatasourc;"
'************************  
'ADO environment is Initialised here  
'*************************  
Function ADOINI(strDB2Cn)  
  With objConnection  
        .Open strSQLCn  
        .CursorLocation=adUseClient  
  End With  
  If objConnection.Errors.Count > 0 Then  
        ErrorOut "Conncetion has Failed."  
  End If  
  With objCommand  
        .ActiveConnection = objConnection  
        .CommandType = adCmdText           
  End With    
End Function  
'********************    
'Execute ADO Comand  
'strSQL - SQL Statment to execute     
'Return ADO RecordSet.  
'*******************************    
Function Exec(strSQL)  
    objCommand.CommandText = strSQL  
    Exec=objCommand.Execute  
End Function  
'******************************************    
    Function ErrorOut(errMsg)  
        Wscript.StdErr.Write Now()&" "&errMsg&vbCrLf   
    End Function  
'****************    
    Function StdOut(msg)   
        WScript.StdOut.Write Now()&" "&msg&vbCrLf   
    End Function  
'************************  

I am using a trial.wsf file , to getback a recordset on which i am trying to loop

<?xml version="1.0" encoding="utf-8" ?>  
<package xmlns="http://schemas.microsoft.com/WindowsScriptHost">  
<job id="main">  
<object id="objConnection"  progid="ADODB.Connection" />  
<object id="objCommand"     progid="ADODB.Command" />  
<object id="objError"       progid="ADODB.Error" />  
<reference object="ADODB.Connection" />  
<reference object="ADODB.Command" />  
<reference object="ADODB.Error" />  

<script language="VBScript" src="lib.vbs">  

    ADOINI(ADOCon)      
    Set objRS = Exec("SELECT REF_CRSETTINGS.NAME, REF_CRSETTINGS.VALUE FROM   WMRCR.REF_CRSETTINGS REF_CRSETTINGS WHERE TRIM(UPPER(REF_CRSETTINGS.CATEGORY)) IN   ('SAMPLE_SETTINGS') ORDER BY REF_CRSETTINGS.CRSETTINGSCODE")  

' the above recordset is a name value pair based on the category   

 StdOut objRS("NAME").Value 'this worked fine  

objRS.MoveNext ' this doesnt work neither does check for EOF or BOF   

</script>  
</job>  
</package>  

My intial thinking was that the cursor type might be wrong ,
but i am not even able to set the cursosr type to dynamic , got a vbscript error not supported .

maybe its an issue with the provider , but am not able to confirm that .

I want to do something like this , but am not able to loop on the recordset ..

  Do While Not objRS.EOF  
    Select Case UCase(trim(objRS("NAME").Value))  
      Case "SOAPSERVER"   SOAPSERVER=objRS("VALUE").Value  
      Case "SOAPMESSAGE"   SOAPMESSAGE=objRS("VALUE").Value  
      Case "SOAPACTION"   SOAPACTION=objRS("VALUE").Value  
      Case Else   ErrorOut "Error: InCorrect Value"  
     End Select  
        objRS.MoveNext  
    Loop  

Am sure there is something basic/silly mistake over here , not well versed with wsf and scripting ..

A Function is a named piece of code that returns something via (in VBScript) assigning to the Function's name. Most of the 'functions' in your library don't and therefore aren't.

The Function Exec tries to return a recordset, ie an object. Object assignment in VBScript need Set . So:

Function Exec(strSQL)  
    objCommand.CommandText = strSQL  
    Set Exec=objCommand.Execute  
End Function  

Based on the KB article mentioned in a comment, you may just want to dump the recordset into an array using. GetRows and process the array. Check this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM