AGI +PERL + festival tts + DBI Freetds SQL SERVER

Hello. I am developping an aplication than execute a query to a MS SQL server database and return the results trougth Festival Text to speech. Well. when i write a perl scripto to connect to the Database (Trougth Freetds), it works fun. In the otehr hand. I already have installed asterisk-perl library, and my agi scripts can excecute festival tts… But when i try the final program that mix the two things.(Connexion to the database and respopnse via festival text to speech). it finish and the agi Hung Up exactly in the line when it connects to the database… Is there anyone that can help me…? The code of my agi is the follow::

#!/usr/bin/perl -w

use Asterisk::AGI;
use DBI;

$AGI = new Asterisk::AGI;

my %input = $AGI->ReadParse();
my $finished = 0;+

#The program ask for the code numbers
$AGI->exec(‘Festival’, ‘“Please send the numbers…”’);

my $numbers = ‘’;
my $x = 0;
while (!$finished) {
my $input = chr($AGI->wait_for_digit(‘2000’));
if ($input =~ /^[0-9*#]$/) {
$numbers .= $input;
} else {
#Tiempo fuera
$finished = 1;


$dbh = DBI->connect(“DBI:Sybase:server=”,“sa”,“password”);
$dbh->do(“use Mydatabase”);


$action = $dbh->prepare(“select,,table1.saldo
from table1
where campo = $numero )”);

my $action->execute ;

@first = $action->fetchrow_array;
$name = $first[1];
$saldo = $first[2];

#SEND the result via Text to peech:
$AGI->exec(‘Festival’, ““Your name is: $name””);
$AGI->exec(‘Festival’, ““Your saldo is: $saldo””);

##Sorry for my English… i am form Peru…!
##Thanks for your hekp
##Renzo Chavez V.