[EMAIL PROTECTED] wrote:
All,did you set dbcc traceon( 3604 ) first ? Doesn't appear below. The traceon ( 3604 ) sends the output to the client, otherwise it falls into the error log of the server.
Several days ago, I learned how to use the odbc_err_handler subroutine provided by DBD::ODBC... in order to capture the 'message' spit out for non-DDL/DML commands in a SQL Server, such as 'backup' or 'dbcc'.
The first batch of commands tested were a variety of backup commands and then DBCC CHECKDB... and the output was all in the variable, as expected...
But then I tested a DBCC INDEXDEFRAG.... in the Query Analyzer it spews out some output (not much)... but when I run it thru my process, no output is returned...
Anybody have any clues? Code snippet below..
L ******************** Snippet for connection:
$dbh_actions = DBI->connect ("dbi:ODBC:Driver={SQL Server};Server=$action_server;Trusted_Connection=yes;",'','', { PrintError => 0, RaiseError => 0, LongReadLen => 65536, odbc_async_exec => 0, odbc_err_handler => sub { my ($state, $msg) = @_; # Strip out all of the driver ID stuff $msg =~ s/^(\[[\w\s]*\])+//; $err_text .= $msg."\n"; return 0; } } );
Snippet to execute:
sub just_do_it
{
my $command = shift;
my $sth = $dbh_actions->prepare($command);
my $rc;
print "** command in sub: $command \n";
if ( $sth )
{
$rc = $sth->execute(); # This is the 'do it'.....
if ( ! $rc ) # Error
{
# Save error messages to email
$err_msgs{"GROUP: $group_name - ITEM: $item_id"} = "Command executed:
$command\n-------------------------------------\nError
Message:\n$err_text";
}
}
else
{
# Save error messages to email $err_msgs{"GROUP: $group_id - ITEM: $item_id"} = "Command executed:
$command\n--------------------------------------\nError
Message:\n$err_text";
}
print "\nCOMMAND OUTPUT:\n$err_text\n";
$err_text = '';
return $rc;
HTH,
Chuck