my $ODBC = DBCCMessage->new(); $ODBC->open ( qq{dbi:ODBC:driver={SQL Server};Server=127.0.0.1;database=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 ( $_ =~ /connection/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 database, 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 (21575115, 1)}); $dbConnection{$ident}->{odbc_err_handler} = \&{$self->err_handler()}; $dbConnection{$ident}->{odbc_async_exec} = 1; $sth->execute(); } } 1;