I'm on a FC3 box with DBD-ODBC-1.16, DBI-1.605, unixODBC-2.2.9-1 , freetds-0.82 and perl 5.8.5. I'm struggling on connect Perl on Linux to Microsoft SQL Server 2000. I can successfully access MS SQL Server from a Perl script and do the single statement query. While I do the multiple concurrent statements on MS SQL Server, it only returned the 1st query result and complained
DBD::ODBC::st execute failed: unixODBCFreeTDSSQL ServerInvalid cursor state (SQL-24000) at fetch_ptu.pl line 38.
I tried following ways

1. add { RaiseError => 1, odbc_cursortype => 2} to my connection

my script halted until timeout. 

2. setting of SQL_ROWSET_SIZE sql_rowset_size / odbc_SQL_ROWSET_SIZE to a value > 1

It complained 

DBD::ODBC::db STORE failed: unixODBCFreeTDSSQL ServerInvalid option (SQL-HY092) at fetch_ptu.pl line 8.

And returned 1st query with complaint Invalid cursor state
56778   2008062300      8061    206     75
DBD::ODBC::st execute failed: unixODBCFreeTDSSQL ServerInvalid cursor state (SQL-24000) at fetch_ptu.pl line 38.

3. $dbh->{odbc_exec_direct} = 1

It also didn't make sense.

I did hard search on Internet, but failed to make sense. Are there any missing?
Could anyone can give me kindly help?
thanks
Jerry
Here are my code
#!/usr/bin/perl use DBI ; my $dbh = DBI->connect("DBI:ODBC:$DSN",$user,$passwd) or die "Can't co +nnect to $DSN: $DBI::errstr" ; #$dbh->{odbc_sql_rowset_size} = 2; #$dbh->{odbc_SQL_ROWSET_SIZE} = 2; #$dbh->{SQL_ROWSET_SIZE} = 2; #$dbh->{sql_rowset_size} = 2; #$dbh->{odbc_exec_direct} = 1; #$dbh->{odbc_cursortype} = 2; $dbh->do("use $database"); my $sql = qq/SELECT StationNum, ObservTimes, StationPress, DryBulTemp, + RelHumidity FROM tabTimeData /; $sql .= qq/ WHERE StationNum= ? /; $sql .= qq/ AND ( ObservTimes >= ? AND ObservTimes <= ?) / ; $sql .= qq/ ORDER BY ObservTimes ASC/ ; my $sth1 = $dbh->prepare($sql) or die "Can't prepare statement: $DBI:: +errstr"; $sql = qq/SELECT StationNum, ObservTimes, StationPress, DryBulTemp, Re +lHumidity FROM tabRealTimeData /; $sql .= qq/ WHERE StationNum= ? /; $sql .= qq/ AND ( ObservTimes >= ? AND ObservTimes <= ?) / ; $sql .= qq/ ORDER BY ObservTimes ASC/ ; my $sth2 = $dbh->prepare($sql) or die "Can't prepare statement: $DBI:: +errstr"; $sth1->execute(($SN,$sEPOCH,$eEPOCH)) ; while ( my @row00 = $sth1->fetchrow_array ) { my ($STID,$EPOCH,$P,$T,$U) = @row00; print "$STID\t$EPOCH\t$P\t$T\t$U\n"; $sth2->execute(($SN,${sEPOCH}.'00',${eEPOCH}.'59')) ; while ( my @rownn = $sth2->fetchrow_array ) { ($STID,$EPOCH,$P,$T,$U) = @rownn; print "$STID\t$EPOCH\t$P\t$T\t$U\n"; } $sth2->finish; } $sth1->finish; $dbh->disconnect if ($dbh) ; exit(0);

In reply to ODBC Error - Invalid Cursor State (SQL-24000) by jerryleo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.