Asterisk CDR into MS SQL db


We have already installed asterisk with elastix (mysql) in our intranet and seems to work like a charm so far.
I am looking for a solution to add CDR records into a local MS-SQL database in order to migrate them with CRM.

At the beggining i was trying to make use of master.csv with a cronjob that would read & insert the csv in to the MS-SQL but i realized that first of all not all records are saved in it and asterisk has already another solution for what i need.

I found that cdr_adaptive_odbc.conf & cdr_odbc.conf seem to support such solutions but i am not sure how exactly to make it work and how to setup the configuration.
Anyone tried or made this work so far?

Thanks in advance,

There you go

be sure to follow the steps for ms-sql or else it wont work.

Hi @astbox,

thanks for the reply. Just to make it clear, configuring odbc doesnt change anything of the current setup will just add another db where asterisk will have access to store cdr records as it does on mysql. Is that right?

Thanks in advance,

Well I don’t think it will chang but I haven’t tested what happens, don’t expect records to populate both databases. From what I know, the local database will be used either way but the remote db part I am guessing will have to be hacked into the diaplan of Elastix to be executed.

Hi @astbox,
you wrote that

don’t expect records to populate both databases

What do you mean? What should i expect then? Thats the reason i am getting into this, if cant manage to populate correctly MSSQL db in order to import all data to crm then i should look for an alternative.


I ment that just enabling the new database won’t do the trick. You have to write also the diaplan to make this happen.

To connect to MS SQL, you need to install the FreeTDS drivers using the package manager (or by compiling via the source files available at

On CentOS: $ sudo yum install freetds,

After installing the drivers, you need to configure the /etc/odbcinst.ini file, which tells the system where the driver files are located.

Once you’ve configured the drivers, you need to modify the /etc/odbc.ini file to control how to connect to the database.

I havent use freedtds, but the steps are clearly described on the above link. if you cant manage to do the conection through the configuration files you can install freedts driver and use the Asterisk system() command to write the dr variables to an external file

So actually the link describes how to make the connection with a MS-SQL db and not to populate the data with all the cdr records in a MS-SQL. Seems easier to start working in another solution, probably via cdr_custom.conf and setting a job that will include data. I expected asterisk to have a more straight-forward solution about adding cdr to other systems.