Hi,

I'm building a 'thread safe' class to running dbcc on MS SQL servers and translate the result on something readable and storeable. I got a example on DBD::ODBC package about how can I handle the DBCC message and his example is working well on a single program, but I still in trouble where talk about my class.

On code bellow, is a sample of how I'd like to get my class working, but I couldn't get the handle error as i want.

I have no more idea about how solve this problem. Maybe have no solution, or someone here can.

Thanks to much,

my $ODBC = DBCCMessage->new(); $ODBC->open ( qq{dbi:ODBC:driver={SQL Server};Server=127.0.0.1;databas +e=Northwind;Truted Connection=yes} ); my %s_ADO = $ODBC->get_index_fragmentation(); package DBCCMessage; use Class::Std; use Class::Std::Utils; { use DBI; use strict; my %dbConnection : ATTR; my %recordSet : ATTR; my %objError : ATTR; sub BUILD { my ( $self, $ident, $startString ) = @_; if ( $startString ) { my ( $stringConnection ) = map { $startString->{$_} if ( $_ =~ /conne +ction/i ) } keys %{$startString}; $self->open( $stringConnection ) if ( $stringConnection ); } } sub open { my ( $self, $conString ) = @_; $dbConnection{ident $self} = DBI->connect ( $conString, qq{}, qq{} ) or die qq{Can't connect to dat +abase, erro : $DBI::errstr}; } sub err_handler { my ( $self, $state, $msg, $nativeerr ) = @_; $msg =~ s/^(\[[\w\s:]*\])+//; push @{$objError{ident $self}}, $msg; return 0; } sub get_index_fragmentation { my $self = shift; my %return; my $ident = ident $self; my $sth = $dbConnection{$ident}->prepare(q{DBCC SHOWCONTIG (215751 +15, 1)}); $dbConnection{$ident}->{odbc_err_handler} = \&{$self->err_handler( +)}; $dbConnection{$ident}->{odbc_async_exec} = 1; $sth->execute(); } } 1;
Solli Moreira Honorio
Sao Paulo - Brazil

In reply to Handling DBD::OBDC error on a 'thread safe' class by shonorio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.