I'am having trouble using the odbc_err_handler callback mechanisme. I really would
like to retrieve informational messages from stored-procedures (as wel as resultsets).
I'am using perl 5.6.1, MSSQL-server 2000, DBI v1.37 and DBD::ODBC v1.06. When there
is more than one informational message, I get an invalid cursor message.
Here's the code i use
use strict;
use DBI;
my $usr = 'sa';
my $pwd = 'blahblah';
my $srv = 'radar01';
my $dsn = "driver={SQL Server};Server=$srv;database=ETL;uid=$usr;pwd=$pwd;";
my $dbh = DBI->connect("dbi:ODBC:$dsn",'','', { PrintError => 1 } ) || die "Can't
connect: $DBI::errstr\n";
$dbh->{odbc_async_exec} = 1;
$dbh->{odbc_err_handler} = \&msg_handler;
my $sth = $dbh->prepare(<<SQLEND);
print 'this is test 1'
print 'this is test 2'
SQLEND
my $rc = $sth->execute;
$sth->finish;
$dbh->disconnect;
sub msg_handler {
my ($state, $msg, $h) = @_;
print "$h\n";
$msg =~ s/^(\[[\w\s]*\])+//;
if ($state ne '01000') {
print "**** $msg\n";
} else {
print "$msg\n";
}
return 0;
}
This results in the following output:
this is test 1
**** De cursorstatus is ongeldig
DBD::ODBC::st execute failed: (DBD: dbd_describe/SQLNumResultCols err=-1) at
D:\temp\perl\web\dbi_tst.pl line 20.
"De cursorstatus is ongeldig" is dutch for "cursor status not valid"
any ideas?
thanks in advance
Pieter
[EMAIL PROTECTED]