spstansbury has asked for the wisdom of the Perl Monks concerning the following question:
Monks,
I have inherited some SQL and would like some input.
I am processing some cable modem stats. Client machine is Windows Server 2008 R2, ActivePerl 5.8, using the ODBC Data Source Administrator control panel.
Script runs fine, but occasionally it exits with the following:
DBD::ODBC::st execute failed: [MySQL][ODBC 5.1 Driver][mysqld-5.1.45-community-log]Lost connection to MySQL server during query (SQL-08S01) at load_modem.wpl line 255.
Please note: I respect the Monastery's preference for actual code, but in interest of inappropriate disclosure, I have modified the following slightly. The logic has not been altered.
use strict; use warnings; use DBI; my $dbh = DBI->connect("dbi:ODBC:MySQL_for_modem"); $dbh->{LongReadLen} = 512 * 1024; $dbh->{LongTruncOk} = 1; my $sql_region_id = "select distinct region_id from config.object "; my $sql_statement = "select info from database"; unless ( $region_cursor = $dbh->prepare( "$sql_region_id" )){ exit 1; } unless ( $region_cursor->execute ) { exit 2; } $region_cursor->bind_columns(\($region_id)); while( $region_cursor->fetch() ){ unless ( $cursor = $dbh->prepare( "$sql_statement" )) { exit 1; } unless ( $cursor->execute($region_id) ) { # <-- line 255 in the sc +ript exit 2; } $cursor->bind_columns(\( $modem_ip, etc... )); while( $cursor->fetch() ) { process the stats... } }
Given that I have no control over the server that I am querying, what is the best way to have the script carry on? ie: instead of the exits (or dies if I replace them), what is a clean way to reconnect and and continue?
As always, thanks for any help and references...
Scott...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Lost connection to MySQL server
by onelesd (Pilgrim) on Aug 30, 2011 at 05:49 UTC | |
by spstansbury (Monk) on Aug 30, 2011 at 16:16 UTC | |
|
Re: Lost connection to MySQL server
by Neighbour (Friar) on Aug 30, 2011 at 06:50 UTC | |
by spstansbury (Monk) on Aug 30, 2011 at 16:23 UTC | |
by locked_user sundialsvc4 (Abbot) on Aug 31, 2011 at 01:08 UTC | |
by afoken (Chancellor) on Aug 31, 2011 at 04:00 UTC | |
by Neighbour (Friar) on Aug 31, 2011 at 06:56 UTC | |
|
Re: Lost connection to MySQL server
by locked_user sundialsvc4 (Abbot) on Aug 29, 2011 at 22:04 UTC | |
by spstansbury (Monk) on Aug 30, 2011 at 16:14 UTC | |
|
Re: Lost connection to MySQL server
by Neighbour (Friar) on Aug 31, 2011 at 06:59 UTC |