Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

MS Access and Win32::ODBC problem

by Washizu (Scribe)
on Aug 30, 2002 at 19:34 UTC ( [id://194224]=perlquestion: print w/replies, xml ) Need Help??

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

Monks,
I'm currently developing a Perl/CGI app that uses an MS Access database. To connect to the database, I'm using the Win32::ODBC module (I'd rather use DBI, but right now I must use Win32::ODBC).

The problem:
The app breaks when I send an SQL statement to the database and it returns more than 246 records. No error message is sent out.

The Code:

my $sqlStatement = "SELECT * FROM databaseName ORDER BY ID"; # Making the database connection my $dbh = new Win32::ODBC("User") or die "Couldn't connect to database: " . DBI->errorstr; if ($dbh->Sql($sqlStatement)){ print "SQL failed!.\n"; print "Error: " . $dbh->Error() . "\n"; $dbh->Close(); exit; } my @dates = (); my %Data = (); # Loop through the recordset, put the data into our array, then do wit +h it as we please while( $dbh->FetchRow() ) { %Data = $dbh->DataHash(); push( @dates, $Data{myDateTime} ); } # Say goodbye to the database $dbh->Close();

What I have tried:

  1. Using this select statement works: "SELECT TOP 246 datetime FROM myDatabaseName ORDER BY ID".
  2. Taking %Data = $dbh->DataHash(); out of the while( $dbh->FetchRow() ){} loop works unless I call FetchRow more than 246 times.
  3. I've tried raising the maximum buffer size $dbh->SetMaxBufSize(3024000); with no success.
  4. If I neglect to call %Data = $dbh->DataHash(); then the while loop iterates the correct number of times.

Where I think the problem could lie:

  1. My own mistake that someone can hopefully point out
  2. A Win32::ODBC bug
  3. An MS Access bug
  4. A server setting preventing large database queries
  5. An MS Access setting preventing large database queries
Any help would be greatly appreciated.

-----------------------------------
Washizu
http://www.bengarvey.com

Corrected sql per author's req. - dvergin 2002-08-31

Replies are listed 'Best First'.
Re: MS Access and Win32::ODBC problem
by gav^ (Curate) on Aug 30, 2002 at 20:51 UTC
    I think the problem you may be having is that the data returned by the 246th row is too big to fit in the buffer. I've had similar problems with Access. If raising the buffer past 3,024,000 bytes is not a possibility you should look at reducing the amount of columns returned. It also seems wasteful to do a 'SELECT *' and only use one column.

    Hope this helps...

    gav^

      Good ideas, but nothing seemed to help. I tried selecting different sets of data from the table and all of them seemed to break at 240-250 records. I tried selecting only a single column and that didn't work either. Thanks for the suggestions.

      -----------------------------------
      Washizu
      Acoustic Rock

Re: MS Access and Win32::ODBC problem
by demerphq (Chancellor) on Aug 30, 2002 at 19:57 UTC
    An important first step to tracking this down would be to turn on ODBC tracing in your ODBC panel. Then run your code. Then turn it off (dont forget!) Then spend some time analyzing the trace ouput. You will probably find that perls regexes come in useful.... At bare minimum this will give you better idea as to which component is responsible for your trouble.

    :-)

    Yves / DeMerphq
    ---
    Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)

      I don't have access to machine because it's in a remote location.

      -----------------------------------
      Washizu
      The best offense is a good offense.

Re: MS Access and Win32::ODBC problem
by richardX (Pilgrim) on Sep 01, 2002 at 14:30 UTC
    I do not use Win32:ODBC, since I have had trouble with it. I use fetchrow_hashref and then I get just the columns I need and push them into my keeper stack. In the following example, Phoophoo is the name of the MS Access database configured under ODBC and X_Master is the name of the table. Here is a snippet of the code that I use:
    use DBI; my $dbh = DBI->connect( "dbi:ODBC:phoophoo", "", "", {RaiseError => 1, PrintError => 1, AutoCommit => 1} ) or die "Unable to connect: " . $DBI::errstr . "\n"; my $sql="SELECT col_one FROM X_Master WHERE col_one <> ''"; print "$sql\n" if $VERBOSE; my $sth = $dbh->prepare($sql) || die $dbh->errstr(); $sth->execute() || die $sth->errstr(); while( my $row = $sth->fetchrow_hashref ) { push @new_col, $row->{col_one}; } $sth->finish(); $dbh->disconnect;

    Richard

    There are three types of people in this world, those that can count and those that cannot. Anon

Re: MS Access and Win32::ODBC problem
by bilfurd (Hermit) on Aug 30, 2002 at 19:41 UTC
    What does it do when it breaks?

      It re-displays the last successful page that was generated, so it will look like no changes have been made to it since it last worked.

      P.S. I know the Select statement should be "SELECT * FROM databaseName..." and I'm trying to figure out how to edit a node to fix it.

      -----------------------------------
      Washizu
      http://www.bengarvey.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://194224]
Approved by myocom
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 20:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found