in reply to MS SQL problem

Try adding the following line:
my $sthB_A = $dbh->prepare($Command) or die "Couldn't prepare query: ".$dbh->errstr; $sthB_A->execute() or die "Couldn't execute query: ".$sthB_A->errstr +; #### $sthB_A->finish(); #### my $Return_results = "...";

Certain DBD::* modules cannot handle more than one open sth for a given dbh. I've never run into it, but I've heard of some who have.

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^2: MS SQL problem
by disciple (Pilgrim) on Dec 10, 2004 at 17:10 UTC

    dragonchild is correct.

    Funny thing is I was just reading about this last night in my "Programming the Perl DBI" book. It says if a statement handle is opened and has not been "finished" you will get the following warning when trying to reuse the statement handle: "disconnect invalidates 1 active statement handle (either destroy statement handles or call finish on them before disconnecting)". If you are fetching from a statement handle and you fetch the last row, the finish method is called for you. On the other hand if you do not fetch all the rows and try to reuse the statement handle you get the following warning: "disconnect invalidates 1 active statement handle (either destroy statement handles or call finish on them before disconnecting)".

    What I didn't read in the book is this. If you attempt to reuse the database handle when a statement handle is open and not finished you get the error: "st execute failed: [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt". This may only be the case with MS SQL, but I am not sure.

    When I executed equivalent code you posted with warnings turned on, I got both the error you posted and the warning I posted.

    Update: Put code tags around error message to fix output.

Re^2: MS SQL problem
by mpeppler (Vicar) on Dec 10, 2004 at 19:12 UTC
    DBD::Sybase is one of those, though it will normally fake it by opening additional database connections "under the covers".

    This is essentially a limitation of the TDS protocol that both Sybase and MS use.

    Michael