Calling stored procedure in MSSQL from Asterisk

Hi Everyone,

I managed to connect MSSQL server to asterisk using Easysoft ODBC driver. I am wondering how I can call a stored procedure in sql server from Asterisk. I created a stored procedure named sp_GetText in sql server.

Please let me know the ways it can be done.

I couldn’t find much information in internet regarding this.

Thanks in advance. Any help highly appreciated.


use the Pear library [] and particularly the MS ADO support package []. You can then access Pear through the scripting language of your choice [php, perl etc] using the Pear package for MS databases

In general I have had a lot better luck working the other way around, pushing data from MSSQL to asterisk than the other way around.

Good luck!

What are you trying to accomplish? You can do the actual calling of the stored procedure in an AGI script if needed.

Hi Dave,

I am bit newbie to calling procedure from Asterisk. Can you please tell what need to done to call a procedure using AGI script.


1st thing you should do, is figure out how to call a stored procedure in the language you are writing the AGI in. Whether that be Perl, PHP, Python, etc… Once you can do that outside of asterisk. Then look into AGI programming for that particular language. Chapter 9 of The Future of Telephony covers it a bit.

Thanks Dave. Your help highly appreciated.
Will let everyone know how it went and also post the code for future reference for others like me.


Hey Guys,

Finally this piece of code did the trick for me

$rs=mssql_query(“declare @a as nvarchar(50)
declare @b as nvarchar(50)
exec sp_xxxxxxxt $phone,@a output,@b output
SELECT @a, @b”);
$row = mssql_fetch_row($rs);

Thanks everyone


I am new to Asterisk. Can u please guide me how to call MS SQL Server stored procedure from Asterisk Dial plan.

Pleae assist.