chandanperl has asked for the wisdom of the Perl Monks concerning the following question:

Dear All, I want to fetch values from stored procedure.I am calling stored procedure from perl script in window system and connecting it to sql server.while running this code it gives me error:Can't call method "Fields" on an undefined value at line $RS = $oSP->Execute(); Please help...

use Win32::OLE; $ConnStr = "DSN=dsn_name;UID=abcd;PWD=password;APP=test;WSID=Mycomp;DA +TABASE=db_name"; $Conn = Win32::OLE->new('ADODB.Connection'); $Conn->Open($ConnStr); #Get record set results from store procedure $oSP = Win32::OLE->new("ADODB.Command"); $RS = Win32::OLE->new("ADODB.Recordset"); $oSP->{'CommandText'} = "exec dbo.sp_reportBytes '%','%','%','%', '200 +9-1-1', '2010-1-1', 'Admin', '530', NULL;"; $oSP->{'CommandType'} = 4; $oSP->{'ActiveConnection'} = $Conn; $oSP->{'CommandTimeout'} = 1200000; $oSP->{'@Param1'} = $Param1; $RS = $oSP->Execute(); while (! $RS->EOF) { $value = $RS->Fields(1)->value; print "$value\n"; $RS->MoveNext; }

Replies are listed 'Best First'.
Re: Running stored procedure through perl script
by Corion (Patriarch) on Mar 04, 2010 at 07:53 UTC

    That line does not contain a ->Fields method call, but the line two lines after contains one:

    $value = $RS->Fields(1)->value;

    This would indicate that $RS is undefined, or that you didn't post the code that produced this error message. I guess that both are true, because the code you posted would die in the function call to ->EOF already..

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Running stored procedure through perl script
by desemondo (Hermit) on Mar 04, 2010 at 08:34 UTC
    using use strict; and use warnings; would probably be a good idea too...

    Update:
    At the very least, $Param1 appears to be undefined, and you are passing its vaue to $oSP->{'@Param1'}...
Re: Running stored procedure through perl script
by Anonymous Monk on Mar 04, 2010 at 07:50 UTC
    Why do you assume that all commands are successful?
    A reply falls below the community's threshold of quality. You may see it by logging in.