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

Hi to all the Monks out there. I'm trying to extract a result from a MS SQL Server Stored Procedure with this code:
use DBI; my $dsn = "Provider=sqloledb;Trusted Connection=yes; Server=$datab +aseHost;Database=$databaseName"; my $sqlDBHandler = DBI->connect("DBI:ADO:$dsn", $databaseUsername, + $databasePassword, {RaiseError=>0,AutoCommit=>1}); my $sqlStatement = 'EXEC GenerateNewPickConfirmationMessage'; my $sqlSelect = $sqlDBHandler->prepare($sqlStatement); $sqlSelect->execute; $sqlResult=$sqlSelect->dump_results(); $sqlDBHandler->disconnect;

As you guessed it my SP is called GenerateNewPickConfirmationMessage, and returns a numeric value. It works well when called from a query in SQL Server, but I get an error from Perl that looks like this: "0 rows (-900: Statement handle not marked as Active.) DBD::ADO::st dump_results failed: Statement handle not marked as Active. at test GetMessageID.pl line 29."

I've searched around and tried a few things, but I always end up with this error. When I set my $sqlStatement variable to a basic select, it works well.

I've read somewhere that ADO needs a select to be "Active" or be able to receive a result.

Anyway, have any Gurus out there experienced something similar or have a simple solutions for me. By the way, I don't have to use ADO, if you feel another driver or package would do the job, I'm open minded.

Thanks

Dan

  • Comment on Retrieving a result from a MS SQL Stored Procedure using DBI and ADO under Win32 Perl
  • Download Code

Replies are listed 'Best First'.
Re: Retrieving a result from a MS SQL Stored Procedure using DBI and ADO under Win32 Perl
by bougon (Novice) on May 27, 2009 at 14:59 UTC

    Issue resolved!!

    I was concentrating on the Perl script when the problem resided in the Stored Proc. A friend suggested I add this at the beginning of by SP "SET NOCOUNT ON" and it solved all my problems. I don't exactly understand what those magic three words mean but I'll look it up later.

      Yes setting "SET NOCOUNT ON" in SP is worked and it produced all my data but at the end it showing an error:

      0 rows (1: no select statement currently executing (SQL-HY000)) DBD::ODBC::st dump_results failed: no select statement currently execu +ting (SQL- HY000) at line
        Thanks for sharing, i've got the same issue, and you can prepend SET NOCOUNT ON to your exec statement if you cannot modify the stored procedure.

        Issue resolved...used for loop instead of while for dump_results