Hello, monks!
I'm not sure it it's a Perl issue, but it is somehow related to it, so i'll give it a try.
I have a Windows 2003 server, and an old database in DBF files, and a need to work with this DB. Numerous scripts are works fine when started from command line, doesn't matter through Win32::ODBC or DBI::ODBC, but when they started from local apache web server (XAMPP, running under the same user), the shows me an error:
ERROR ODBC: [-1022] [] "[Microsoft][ODBC dBase Driver] Disk or network error."or, if i use DBD::ODBC:
ERROR ODBC: [Microsoft][ODBC dBase Driver] Disk or network error. (SQL-HY000)But when i run the same script from command line, everything works fine:
w:\xampp\htdocs>errors.pl 2009-02-27 2005-01-01 2010-01-20 2008-10-01 2012-09-28 2016-08-30 2010-06-18 2010-05-18 2010-03-01 2009-12-23 2010-02-14
the code itself:
my $DSN = "EXDSN"; my $Dir = "e:/db/"; my $Driver = "Microsoft dBase Driver (*.dbf)"; if (!Win32::ODBC::ConfigDSN(ODBC_ADD_SYS_DSN, $Driver, "DSN=$DSN", "Description=DSN", "DBQ=$Dir", "DEFAULTDIR=$Dir", "UID=" )) { die "ERROR ODBC: Can't config Win32::ODBC : ".Win32::ODBC::Error() +; } if ($odbctype eq "DBI") { my $EXDSN = "driver=$Driver;dbq=$Dir;defaultdir=$Dir"; $db = DBI->connect("dbi:ODBC:$EXDSN","","" ); die "ERROR ODBC: ". wenc(scalar $DBI::errstr) ."\n" if not $db; } if ($odbctype eq "WIN32") { $db = new Win32::ODBC( $DSN ); die "ERROR ODBC: ". wenc(scalar Win32::ODBC::Error()) ."\n" if not + $db; } if ($odbctype eq "WIN32") { if ( $db->Sql( "select table.date from table group by table.date o +rder by table.date desc" )) { my $err = $db->Error(); print "Error DBF SQL: " . &enc($err) . "\n"; } else { while($db->FetchRow() ) { my(%Data) = $db->DataHash(); print Dumper(%Data); } } } if ($odbctype eq "DBI") { my $ref_astore = $db->selectall_hashref( "select table.date from t +able group by table.date order by table.date desc",'date' ); if (!defined($ref_astore)) { print "Error DBF: " . $db->errstr . "\n"; exit; } else { print join("\n",keys %{ $ref_astore } ); } }
Although i can have access to *.dbf files and DSN list of ODBC driver from apache. The code:
my $dir = "e:/db/"; if (-d $dir) { print "OK $dir\n"; opendir(my $dh, $dir) || die "Can't opendir $dir: $!"; print join("\n",readdir($dh)); closedir $dh; } my %dsn = Win32::ODBC::DataSources(); foreach my $key (sort keys %dsn) { print "<br>$key $dsn{$key}"; }
gives me the output:
OK e:/db/ . .. TABLE.DBF TABLE2.DBF TABLE3.DBF ... DB Microsoft dBase Driver (*.dbf) DSN Microsoft dBase Driver (*.dbf) EXDSN Microsoft dBase Driver (*.dbf)
What's the problem here?
UPDATE:
SOLVED thanks to Corion. Seems that for ODBC to work it needs TMP environment variable. Setting it in code before ODBC stuff did the trick.
$ENV{'TMP'} = 'C:\\DOCUME~1\\lan\\LOCALS~1\\Temp\\2';| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |