Advertisement

06.24.2008 at 11:06PM PDT, ID: 23513465
[x]
Attachment Details

DBD:ODBC issue - ODBC Error - Invalid Cursor State (SQL-24000)

Asked by Jerryleo in Perl Programming Language, Databases Miscellaneous, MS SQL Server

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: [unixODBC][FreeTDS][SQL Server]Invalid 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: [unixODBC][FreeTDS][SQL Server]Invalid 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: [unixODBC][FreeTDS][SQL Server]Invalid 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
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
#!/usr/bin/perl
 
use DBI ;
 
my $dbh = DBI->connect("DBI:ODBC:$DSN",$user,$passwd) or die "Can't connect 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, RelHumidity 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);
[+][-]06.25.2008 at 06:14AM PDT, ID: 21865157

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Perl Programming Language, Databases Miscellaneous, MS SQL Server
Sign Up Now!
Solution Provided By: sqd5597
Participating Experts: 1
Solution Grade: B
 
 
[+][-]07.02.2008 at 05:40AM PDT, ID: 21915686

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]07.03.2008 at 09:34AM PDT, ID: 21927068

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628