safe_asterisk problem with MySQL Connection

Hi,

I'm using Asterisk 1.2.7.1 and using MySQL Database. I'm using few set of AGI files for accessing MySQL DB tables at different points of the Dial plan. I'm facing a strange issue. When i start asterisk in the command line as "asterisk -dvvvvvvvvg -c". It starts up and it accesses MySQL DB tables properly but, when i start asterisk using safe_asterisk shell script it starts up but wherever it accesses MySQL DB the connection fails. Any idea - why this happens?

Pls help me in solving this problem.

Thanks,
Rajesh.