Jenda has asked for the wisdom of the Perl Monks concerning the following question:
I have code like this
to run the DBCC CHECKDB and capture the messages. It works perfect. I'd like to do the same thing for a stored procedure (some daily database maintenance task) that prints some headings and the counts of rows affected when run via the Query Analyzer, but can't seem to be able to do so. If I replace the "dbcc CHECKDB ('$database')" by "EXEC dbo.dbAdm_Daily" I getsub DBCC { my $database = shift(); my $text = ''; my $dbh = DBI->connect('dbi:ODBC:jobodbc2', 'xxxx', 'xxxx', {PrintError => 0,RaiseError => 1,LongReadLen => 65536, odbc_async_exec => 1, odbc_err_handler => sub { my ($state, $msg) = @_; # Strip out all of the driver ID stuff $msg =~ s/^(\[[\w\s]*\])+//; $text .= $msg."\n"; return 0; } }); my $sth = $dbh->prepare("dbcc CHECKDB ('$database')"); $sth->execute; $dbh->disconnect(); return $text; }
DBD::ODBC::st execute failed: (DBD: dbd_describe/SQLNumResultCols err= +-1)
The procedure works when started from QueryAnalyzer and prints the messages. It works as well if called with $dbh->do(), but the messages are not captured in this case. What am I doing wrong?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI+MS SQL, capture prints from stored procedures
by mikasue (Friar) on Apr 24, 2006 at 14:52 UTC | |
by Jenda (Abbot) on Apr 24, 2006 at 21:34 UTC | |
by meredith (Friar) on Apr 27, 2006 at 03:59 UTC | |
by Jenda (Abbot) on Apr 27, 2006 at 11:10 UTC |